Free Practice Quiz Question List

05 Functions Online Quiz Questions

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

20 questions
01
Choose one
1 point

Why can a function declaration allow a call to appear before the function's definition in a C++ source file?

  1. A

    It executes the function body immediately.

  2. B

    It allows the function to be called before its definition appears.

  3. C

    It permanently stores the function's return value.

  4. D

    It changes all parameters to reference parameters.

02
Choose one
1 point

Given void increase(int value) { ++value; }, what is the value of number after this code executes?

int number = 10;
increase(number);

  1. A

    The caller's variable becomes 11 because every parameter is passed by reference.

  2. B

    The program is ill-formed because an integer cannot be passed to a function.

  3. C

    The caller's variable remains 10 because the parameter is passed by value.

  4. D

    The function changes the caller's variable only after it returns.

03
Choose one
1 point

Consider these overloads:

int area(int side)
double area(double radius)

Which overload is selected for the call area(5)?

  1. A

    double area(double radius) because double is more general than int.

  2. B

    Both overloads are called and their results are compared.

  3. C

    int area(int side) because the argument 5 has type int.

  4. D

    Neither overload can be selected because overloaded functions must have different names.

04
Choose all
1 point

Which differences can distinguish valid C++ function overloads? Select all correct choices.

  1. A

    The number of parameters

  2. B

    The parameter types

  3. C

    The return type alone

  4. D

    The order of parameter types

05
Choose all
1 point

Which properties are necessary for a practical recursive function? Select all correct choices.

  1. A

    A base case that stops further recursive calls

  2. B

    A recursive case that works on a smaller or simpler problem

  3. C

    A different function name for every recursive call

  4. D

    Eventual termination before available stack space is exhausted

06
True or false
1 point

True or false: A C++ function declared with return type void may use return; to exit early, but it cannot return a value.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: Returning a local variable by value is safe, whereas returning a pointer or reference to that local variable is invalid after the function ends.

  1. A

    True

  2. B

    False

08
Written response
1 point

What C++ term describes the actual value supplied to a function call, such as 4 and 6 in multiply(4, 6)?

09
Written response
1 point

What integer value does the nested call square(add(2, 3)) produce?

10
Fill in the blank
1 point

Complete the general structure of a C++ function definition:

function_name() { statements }

11
Fill in the blank
1 point

Complete the sentence: A parameter can allow a function to modify the caller's original variable.

12
Open ended
1 point

Explain the difference between a C++ function declaration and definition, including why a declaration can appear before a function call and what must agree between the declaration and definition.

13
Choose one
1 point

What does this program print when showCount() is called twice?

void showCount() {
int count = 0;
++count;
std::cout << count << '\n';
}

  1. A

    It prints 1 and then 2.

  2. B

    It prints 1 twice.

  3. C

    It prints 0 twice.

  4. D

    It prints 2 twice.

14
Choose one
1 point

Which return type should a C++ function use when it does not return a value?

  1. A

    null

  2. B

    void

  3. C

    empty

  4. D

    none

15
Choose one
1 point

What is the main purpose of a function declaration such as int add(int first, int second);?

  1. A

    It executes the function immediately.

  2. B

    It provides the function body.

  3. C

    It tells the compiler the function's name, return type, and parameter types.

  4. D

    It creates a local variable for every parameter.

16
Written response
1 point

What is the C++ term for the variable listed in a function declaration or definition that receives a value from the caller?

17
True or false
1 point

True or false: Returning a reference to a local variable is invalid because the local variable's lifetime ends when the function returns.

  1. A

    True

  2. B

    False

18
Choose one
1 point

Given void increase(int value) { ++value; }, what happens after int number = 10; increase(number);?

  1. A

    The function changes a copy, so the caller's original variable remains unchanged.

  2. B

    The function changes the caller's original variable directly.

  3. C

    The program cannot compile because integers cannot be parameters.

  4. D

    The function changes all variables with the same name.

19
Choose one
1 point

Which function signature allows increase to modify the caller's integer variable directly through a reference parameter?

  1. A

    void increase(int value)

  2. B

    void increase(const int value)

  3. C

    void increase(int* value)

  4. D

    void increase(int& value)

20
Written response
1 point

What integer value is produced by the nested call square(add(1, 2)), assuming add returns the sum of its two arguments and square returns its argument multiplied by itself?