Free Practice Quiz Question List

5 Functions Online Quiz Questions

Use this free practice quiz with 20 questions to review 5 Functions, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Which C++ statement is a function declaration rather than a function definition or function call?

  1. A

    int square(int number) { return number * number; }

  2. B

    int square(int number);

  3. C

    square(5);

  4. D

    return square(number);

02
True or false
1 point

True or false: A C++ function with return type void does not return a value to its caller.

  1. A

    True

  2. B

    False

03
Written response
1 point

In the call add(4, 7), what is the C++ term for each value supplied to the function?

04
Fill in the blank
1 point

A variable declared inside an if block can be used only within that block. This limitation is called .

05
Choose one
1 point

What is the value of value after this program runs?

void try_to_change(int number) { number = 99; }

int value = 10;

try_to_change(value);

  1. A

    value remains 10

  2. B

    value becomes 99

  3. C

    The program fails because assignment to a parameter is illegal

  4. D

    value is destroyed when the function returns

06
Choose all
1 point

Which benefits can result from decomposing a program into several focused functions? Select all that apply.

  1. A

    Each function can be read independently, reducing complexity.

  2. B

    A calculation can be called from several places, encouraging reuse.

  3. C

    Functions no longer need parameters.

  4. D

    Individual functions can be tested with known inputs.

  5. E

    Changing one calculation always requires rewriting input and output code.

07
Written response
1 point

What C++ feature allows functions in the same scope to have the same name while differing in their parameter lists?

08
True or false
1 point

True or false: A parameter declared for one function can normally be used directly in main because parameters have program-wide scope.

  1. A

    True

  2. B

    False

09
Fill in the blank
1 point

A function declaration introduces a function without its body. The version that supplies the body is called a .

10
Choose all
1 point

A task needs to produce several results. Which approaches are identified as reasonable introductory solutions? Select all that apply.

  1. A

    Return a class or structure containing the results.

  2. B

    Modify objects through reference parameters.

  3. C

    Decompose the task into multiple functions.

  4. D

    Change only the function's return type while keeping its parameter list identical.

  5. E

    Use a void return type and assume the caller automatically receives all local variables.

11
Choose one
1 point

Given these overloads, which one is selected by the call maximum(3, 8)?

int maximum(int a, int b);

double maximum(double a, double b);

  1. A

    maximum(int, int)

  2. B

    maximum(double, double)

  3. C

    Both overloads are equally preferred

  4. D

    Neither overload is viable because maximum is overloaded

12
Open ended
1 point

Design a function decomposition for a program that reads a rectangle's length and width, calculates its area, and prints the result. Describe the responsibility and relevant inputs or result of each function.

13
Choose one
1 point

What is wrong with this C++ code?

int add(int, int);

int add(int a) { return a; }

  1. A

    The function name must be capitalized.

  2. B

    The return type must be void.

  3. C

    The declaration and definition describe different parameter lists.

  4. D

    A function cannot be defined after it is declared.

14
True or false
1 point

True or false: The body of a C++ function contains the statements that implement the function's task.

  1. A

    True

  2. B

    False

15
Choose one
1 point

Which part of a C++ function definition supplies the implementation of the function?

  1. A

    The function body

  2. B

    The parameter list

  3. C

    The return type

  4. D

    The function name

16
Written response
1 point

In the call add(4, 7), what C++ term describes each supplied value, such as 4 or 7?

17
Choose one
1 point

A source file defines int add(int first, int second) { return first + second; }. Which declaration correctly matches that definition?

  1. A

    void add(int);

  2. B

    int add(int, int);

  3. C

    double add(double, double);

  4. D

    int add();

18
Choose one
1 point

Given the function double half(int value) { return value / 2.0; }, what value does half(5) return?

  1. A

    2

  2. B

    2.5

  3. C

    3

  4. D

    5

19
Choose one
1 point

Consider int difference(int a, int b) { int result = a - b; return result; }. Which statement correctly describes where the name result can be used?

  1. A

    result can be used anywhere after difference is called.

  2. B

    result is available in main because it is returned.

  3. C

    result can be used only inside difference.

  4. D

    result is a global variable because it has an int type.

20
Written response
1 point

What numeric value is returned by half(5) when half is defined as double half(int value) { return value / 2.0; }?