Name:
Class:
Date:
Page 1
Indicate whether the statement is true or false.
1. While a void function does not return a value, it must still end with a return statement.
a.
True
b.
False
2. Void functions return a value after completing their task.
a.
True
b.
False
3. You pass a variable by value when you want the receiving function to change the contents of the variable.
a.
True
b.
False
4. The srand function, that initializes the C++ random number generator, is an example of a void function.
a.
True
b.
False
5. All built-in and program-defined functions are categorized as either value-returning functions or void functions.
a.
True
b.
False
6. An actual argument can be a variable, named constant, literal constant, or keyword.
a.
True
b.
False
7. Passing by reference is when you pass a copy of a variable’s value to a function.
a.
True
b.
False
8. Passing by value is when you pass a copy of a variable’s address to a function.
a.
True
b.
False
9. A typical call to a void function will look like the following code:
area = getArea(side1, side2);
a.
True
b.
False
10. When you pass a variable by reference, the called function can change the contents of the variable.
a.
True
b.
False
Indicate the answer choice that best completes the statement or answers the question.
Name:
Class:
Date:
Page 2
11. The arguments that are passed to a function are referred to as which of the following?
a.
formal arguments
b.
actual arguments
c.
corresponding arguments
d.
required arguments
12. What is the first part to the function definition of a void function?
a.
function body
b.
function header
c.
return statement
d.
ending comments
13. Which of the following is NOT required in a void function?
a.
function header
b.
function body
c.
return statement
d.
ending brace
14. Unless you specify otherwise, in what manner are variables passed to functions?
a.
by value
b.
by reference
c.
by invocation
d.
by parameter
15. Only functions defined where, in relation to the main function, require a function prototype to be coded?
a.
above
b.
below
c.
within
d.
outside
16. Which of the following would be a practical use for a void function?
a.
returning the sum of two numbers
b.
returning the average of two numbers
c.
displaying two numbers
d.
calculating the area of a rectangle
17. Which of the following is a proper declaration of a function that sums and displays two integers and returns no value?
a.
int printSum(int val1, int val2)
b.
void printSum(int val1, int val2)
c.
printSum(void val1, void val2)
d.
int printSum(val1, val2)
18. Which of the following is true about the relationship between the actual parameter and the corresponding formal
parameter?
a.
their data types can be different
b.
their names must be the same
c.
their names can be different
d.
their values must be the same
19. Sending a copy of a variable’s value to a function is referred to as which of the following?
a.
passing by value
b.
passing by reference
c.
passing by invocation
d.
passing by parameter
20. Which of the following tells the computer to pass the variable’s address rather than a copy of its contents?
a.
value-returning function
b.
return statement
c.
address-of operator
d.
referral operator
21. If you want a function to know the contents of a variable, but don’t want the function to modify the value, in what
manner should the variable be passed?
a.
by value
b.
by reference
c.
by invocation
d.
by parameter
Name:
Class:
Date:
Page 3
22. Which of the following is another term for calling a function?
a.
declare
b.
invoke
c.
initialize
d.
instantiate
23. Which symbol is used to represent the address-of operator?
a.
&
b.
$
c.
@
d.
#
24. The function body in a void function is enclosed in which of the following?
a.
parentheses
b.
braces
c.
quotes
d.
asterisks
25. What is the proper function type to use when declaring a function that takes two floating point numbers and calculates
and displays the product with no return value?
a.
float
b.
long
c.
void
d.
double
26. To pass a variable by reference in C++, what must be included before the name of the corresponding formal parameter
in the receiving function’s header?
a.
&
b.
{
c.
>>
d.
%
27. If you want a function to modify the value stored in a variable, how do you need to pass the variable?
a.
by value
b.
by reference
c.
by invocation
d.
by parameter
28. Which of the following is a valid invocation of a value-returning function?
a.
myFunction(y, z);
b.
x = myFunction(y, z);
c.
int myFunction();
d.
myFunction(y, z) = x;
29. What keyword begins the function header of a void function?
a.
data
b.
void
c.
return
d.
int
30. What is the correct statement needed to call a void function named sumIt that changes the value of the variable named
totalSum?
a.
sumIt(&totalSum);
b.
totalSum = sumIt();
c.
void sumIt(totalSum);
d.
@totalSum = sumIt();
31. In a void function, what is true about the return statement?
a.
It is required.
b.
It is always initalizd to 0.
c.
It is not necessary.
d.
You cannot use a return statement.
32. Passing a variable’s unique address to a function is referred to as which of the following?
a.
passing by value
b.
passing by reference
c.
passing by invocation
d.
passing by parameter
Name:
Class:
Date:
Page 4
33. What, if anything is required to fix the following code?
char val1, val2;
val1 = 10;
val2 = 25;
printSum(val1, val2);
void printSum(int x, int y)
{
cout << “The sum is:<< x + y << endl;
}
a.
val1 and val2 should be passed by reference
b.
nothing is required, the code is correct
c.
the x and y variables should be named val1 and val2
d.
val1 and val2 are the wrong type
34. What is the scope of the variables listed in a function?
a.
local to the function
b.
global to the program
c.
referential to the function
d.
global to the main() function
35. What type of functions do not return a value after completing their task?
a.
value-defined
b.
void
c.
loop
d.
all
36. Which of the following looks like a typical call to a void function?
a.
printSum(a, b);
b.
printSum(a, b) = y;
c.
x = printSum(a, b);
d.
printSum[a, b];
37. When passing a variable by reference to a function, must the formal parameters have the same exact name as their
corresponding actual parameters?
38. Is it possible to pass a variable to a function by reference and have the value stored in the original actual parameter
remain unchanged?
39. Write a void function called getAge that has one formal parameter of the int data type. The function should prompt the
user for their age and return the value through the parameter.
An example of the call to the function could be as follows, where the variable age has been declared to be of the int data
type.
getAge(age);
40. What are the two main differences between the syntax for creating a value-returning function and the syntax for
creating a void function?
41. Give an example of a function that would be a good candidate to only utilize variables passed by value.
42. Given the program segments below (one from the main function, and one program-defined function called calcSum),
what would be printed in the main program for the variable sum after the function is called? Assume an appropriate
function prototype has been declared.
Name:
Class:
Date:
Page 5
main function
int num1 = 10;
int num2 = 15;
int sum = 0;
calcSum(num1, num2, sum);
cout << “The value of sum is: << sum << endl; //What is the value of sum
here?
calcSum function code
void calcSum(int num1, int num2, int sum)
{
sum = num1 + num2;
}
//end of calcSum function
43. Write a void function called calcSum that has three formal parameters of the int data type. The function should accept
two integer values to sum in the first two parameters, sum the values, and then return their sum through the third
parameter.
An example of the call to the function could be as follows, where the variables num1, num2, and sum have been declared
to be of the int data type.
calcSum(num1, num2, sum);
44. List the syntax to create a program-defined Void function.
45. What is the only type of argment that can be passed by reference to a function?
46. How does a computer store variables passed by value and variabled passed by reference?
Name:
Class:
Date:
Page 6
Name:
Class:
Date:
Page 7
Name:
Class:
Date:
Page 8