Which C++ statement is a function declaration rather than a function definition or function call?
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.
True or false: A C++ function with return type void does not return a value to its caller.
- A
True
- B
False
In the call add(4, 7), what is the C++ term for each value supplied to the function?
A variable declared inside an if block can be used only within that block. This limitation is called .
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);
- A
valueremains10 - B
valuebecomes99 - C
The program fails because assignment to a parameter is illegal
- D
valueis destroyed when the function returns
Which benefits can result from decomposing a program into several focused functions? Select all that apply.
- A
Each function can be read independently, reducing complexity.
- B
A calculation can be called from several places, encouraging reuse.
- C
Functions no longer need parameters.
- D
Individual functions can be tested with known inputs.
- E
Changing one calculation always requires rewriting input and output code.
What C++ feature allows functions in the same scope to have the same name while differing in their parameter lists?
True or false: A parameter declared for one function can normally be used directly in main because parameters have program-wide scope.
- A
True
- B
False
A function declaration introduces a function without its body. The version that supplies the body is called a .
A task needs to produce several results. Which approaches are identified as reasonable introductory solutions? Select all that apply.
- A
Return a class or structure containing the results.
- B
Modify objects through reference parameters.
- C
Decompose the task into multiple functions.
- D
Change only the function's return type while keeping its parameter list identical.
- E
Use a
voidreturn type and assume the caller automatically receives all local variables.
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);
- A
maximum(int, int) - B
maximum(double, double) - C
Both overloads are equally preferred
- D
Neither overload is viable because
maximumis overloaded
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.
What is wrong with this C++ code?
int add(int, int);
int add(int a) { return a; }
- A
The function name must be capitalized.
- B
The return type must be
void. - C
The declaration and definition describe different parameter lists.
- D
A function cannot be defined after it is declared.
True or false: The body of a C++ function contains the statements that implement the function's task.
- A
True
- B
False
Which part of a C++ function definition supplies the implementation of the function?
- A
The function body
- B
The parameter list
- C
The return type
- D
The function name
In the call add(4, 7), what C++ term describes each supplied value, such as 4 or 7?
A source file defines int add(int first, int second) { return first + second; }. Which declaration correctly matches that definition?
- A
void add(int); - B
int add(int, int); - C
double add(double, double); - D
int add();
Given the function double half(int value) { return value / 2.0; }, what value does half(5) return?
- A
2
- B
2.5
- C
3
- D
5
Consider int difference(int a, int b) { int result = a - b; return result; }. Which statement correctly describes where the name result can be used?
- A
resultcan be used anywhere afterdifferenceis called. - B
resultis available inmainbecause it is returned. - C
resultcan be used only insidedifference. - D
resultis a global variable because it has aninttype.
What numeric value is returned by half(5) when half is defined as double half(int value) { return value / 2.0; }?