Ch 6 Multiple Choice

25 July 2022
4.7 (114 reviews)
48 test answers

Unlock all answers in this set

Unlock answers (44)
question
When a function is called, flow of control moves to the function's prototype.
answer
F
question
A parameter is a special purpose variable that is declared inside the parentheses of a function definition.
answer
T
question
A local variable and a global variable may not have the same name within a program.
answer
F
question
A static variable that is defined within a function is initalized only once, the first time it is called.
answer
T
question
It is possible for a function to have some parameters with default arguments and some without.
answer
T
question
A function's return data type must be the same as the function's parameters.
answer
F
question
One reason for using functions is to break programs into manageable units or modules.
answer
T
question
You must always furnish an argument with a function call.
answer
F
question
Global variables are initialized to zero by default.
answer
T
question
Local variables are initialized to zero by default.
answer
F
question
It is not considered good programming practice to declare all your variables globally.
answer
T
question
You may use the exit() function to terminate a program, regardless of which control mechanism is executing.
answer
T
question
A collection of statements that performs a specific task is a(n) a. infinite loop b. variable c. constant d. function e. decision
answer
D
question
A function __________ contains the statements that make up the function. a. prototype b. definition c. call d. expression e. parameter list
answer
B
question
A function can have no parameters, one parameter, or many parameters and can return __________ value(s). a. zero to many b. no c. only one d. a maximum of ten e. None of these
answer
C
question
A function is executed when it is a. defined b. prototyped c. declared d. called e. None of these
answer
D
question
Functions are ideal for menu-driven programs. When the user selects a menu item, the program can __________ the appropriate function. a. call b. append c. define d. declare e. None of these
answer
A
question
This type of variable is defined inside a function and is not accessible outside the function. a. global b. reference c. local d. counter e. None of these
answer
C
question
The value in this type of variable persists between function calls. a. global b. internal c. static d. dynamic e. None of these
answer
C
question
These types of arguments are passed to parameters automatically if no argument is provided in the function call. a. local b. default c. global d. reference e. None of these
answer
B
question
When used as parameters, these types of variables allow a function to access the parameter's original argument: a. reference b. floating-point c. counter d. undeclared e. None of these
answer
A
question
__________ functions may have the same name as long as their parameter lists are different. a. Only two b. Two or more c. No d. Un-prototyped e. None of these
answer
B
question
This statement causes a function to end. a. end b. terminate c. return d. release e. None of these
answer
C
question
This function causes a program to terminate, regardless of which function or control mechanism is executing. a. exit() b. terminate() c. return() d. continue() e. None of these
answer
A
question
Which of the following causes a function to execute? a. aforloop b. a do-while loop c. a function prototype d. a function call e. None of these
answer
D
question
It is good programming practice to __________ your functions by writing comments that describe what they do. a. execute b. document c. retrieve d. create e. None of these
answer
B
question
A(n) __________ is information that is passed to a function, and a(n) __________ is information that is received by a function. a. function call, function header b. parameter, argument c. argument, parameter d. prototype, header e. None of these
answer
C
question
A function _________ eliminates the need to place a function definition before all calls to the function. a. header b. prototype c. argument d. parameter e. None of these
answer
B
question
A _________ variable is declared outside all functions. a. local b. global c. floating-point d. counter e. None of these
answer
B
question
If a function is called more than once in a program, the values stored in the function's local variables do not _________ between function calls. a. persist b. execute c. communicate d. change e. None of these
answer
A
question
A __________ argument is passed to a parameter when the actual argument is left out of the function. a. false b. true c. null d. default e. None of these
answer
D
question
If a function does not have a prototype, default arguments may be specified in the __________. a. function call b. function header c. execution d. return type e. None of these
answer
B
question
The value in a ____ variable persists between function calls a. dynamic b. global c. floating-point d. static local e. counter
answer
D
question
Given the following function: void calc (int a, int& b) { int c; c = a + 2; a = a * 3; b = c + a; } What is the output of the following code segment that invokes calc(): int x = 1; int y = 2; int z = 3; calc(x, y); cout<
answer
B
question
EXIT_FAILURE and ________ are named constants that may be used to indicate success or failure when the exit() function is called. a. EXIT_TERMINATE b. EXIT_SUCCESS c. EXIT_OK d. RETURN_OK
answer
B
question
This is a dummy function that is called instead of the actual function it represents: a. main b. stub c. a driver d. an overloaded function
answer
B
question
What will the following code display? #include using namespace std; void showDub(int); int main() { int x = 2; showDub(x); cout << x << endl; return 0; } void showDub(int num) { cout << (num * 2) << endl; } a. 2 c. 2 b. 4 2 c. 2 4 d. 4 4
answer
B
question
What will the following code display? #include using namespace std; void doSomething(int); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int num) { num = 0; cout << num << endl; } a. 2 0 2 b. 2 2 2 c. 0 0 0 d. 2 0 0
answer
A
question
What will the following code display? #include using namespace std; void doSomething(int&); int main() { int x = 2; cout << x << endl; doSomething(x); cout << x << endl; return 0; } void doSomething(int& num) { num = 0; cout << num << endl; } a. 2 0 2 b. 2 2 2 c. 0 0 0 d. 2 0 0
answer
D
question
Which line in the following program contains the prototype showDub function? 1 #include 2 usingnamespacestd; 3 void showDub(int); 4 int main() 5{ 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 voidshowDub(intnum) 12 { 13 cout << (num * 2) << endl; 14 } a. line 3 b. line 4 c. line 7 d. line 11
answer
A
question
Which line in the following program contains the header for the showDub function? 1 #include 2 usingnamespacestd; 3 void showDub(int); 4 int main() 5{ 6 int x = 2; 7 showDub(x); 8 cout << x << endl; 9 return 0; 10 } 11 voidshowDub(intnum) 12 { 13 cout << (num * 2) << endl; 14 } a. line 3 b. line 4 c. line 7 d. line 11
answer
D
question
What is the data type of the following function prototype's parameter variable? int myFunction(double); a. int b. double c. void d. cannot tell from the prototype
answer
B
question
What is the data type of the following function prototype's return value? int myFunction(double); a. int b. double c. void d. cannot tell from the prototype
answer
A
question
In the following function prototype, how many parameter variables does this function have? int myFunction(double, double, double); a. 1 b. 2 c. 3 d. cannot tell from the prototype
answer
C
question
What will the following code display? #include using namespace std; int getValue(int); int main() { int x = 2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num + 5; } a. 5 b. 2 c. 7 d. getValue(x)
answer
C
question
Given the following header for a function named computeValue, which of the following is a valid call to the function? void computeValue(int value) a. computeValue(10) b. computeValue(10); c. void computeValue(10); d. void computeValue(int x);
answer
B
question
Select all that apply. Which of the following must be included in a function header? a. the data type of each parameter b. the data type of the return value c. the name of the function d. the names of parameter variables
answer
A, B, C, D
question
Select all that apply. Which of the following statement(s) about global variables is(are) true? a. A global variable is accessible only to the main function. b. A global variable is declared in the highest-level block in which it is used. c. A global variable can have the same name as a variable that is declared locally within a function. d. A global variable is the same as a named constant. e. If a function contains a local variable with the same name as a global variable, the global variable's name takes precedence within the function.
answer
A, B, C, E