C++ Quiz 5

Ace your homework & exams now with Quizwiz!

Given the following function definition: 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 fragment that invokes calc? Select one: a. 1 2 3 b. 1 6 3 c. 3 6 3 d. 1 14 9 e. None of these

b. (1 6 3)

What is the output of the following program? 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; } Select one: a. 2 2 2 b. 2 0 0 c. 2 0 2 d. 0 0 0

b. (2 0 0)

These types of arguments are passed to parameters automatically if no argument is provided in the function call. Select one: a. Local b. Default c. Global d. Relational e. None of these

b. (Default )

________ functions may have the same name, as long as their parameter lists are different. Select one: a. Only two b. Two or more c. Zero d. Un-prototyped e. None of these

b. (Two or more)

A function ________ contains the statements that make up the function. Select one: a. call b. definition c. expression d. prototype e. parameter list

b. (definition)

It is a good programming practice to ________ your functions by writing comments that describe what they do. Select one: a. execute b. document c. eliminate d. prototype e. None of these

b. (document )

If a function does not have a prototype, default arguments may be specified in the function ________. Select one: a. call b. header c. execution d. return type e. None of these

b. (header )

A function ________ eliminates the need to place a function definition before all calls to the function. Select one: a. header b. prototype c. argument d. parameter e. None of these

b. (prototype )

A function can have zero to many parameters, and it can return this many values. Select one: a. zero to many b. no c. only one d. a maximum of ten e. None of these

c. ( only one )

A(n) ________ is information that is passed to a function, and a(n) ________ is information that is received by a function. Select one: a. function call, function header b. parameter, argument c. argument, parameter d. prototype, header e. None of these

c. (argument, parameter)

This is a statement that causes a function to execute. Select one: a. for loop b. do-while loop c. function prototype d. function call e. None of these

d. ( function call )

True/False: A local variable and a global variable may not have the same name within the same program. Select one: True False

f (False)

True/False: When a function is called, flow of control moves to the function's prototype. Select one: True False

f (False)

True/False: A parameter is a special-purpose variable that is declared inside the parentheses of a function definition. Select one: True False

t (True )

True/False: It is possible for a function to have some parameters with default arguments and some without. Select one: True False

t (True )

Which line in the following program contains a call to the showDub function? 3) 4) void showDub (int); 5) 6) int main () 7) { 8) int x=2; 9) 10) showDub(x); 11) cout << x << endl; 12) return 0; 13) } 14) 15) void showDub(int num) 16) { 17) cout << (num*2)<< endl; 18) } Select one: a. 10 b. 4 c. 15 d. 6

a. (10 )

Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function. Select one: a. call b. prototype c. define d. declare e. None of these

a. (call )

What is the output of the following program? void showDub(int) int main() { int x=2; showDub(x) cout << x << endl; return 0; } void showDub(int num) { cout << (num*2)<< endl; } Select one: a. 4 4 b. 2 2 c. 4 2 d. 2 4

c. (4 2 )

Look at the following function prototype. int myFunction(double); What is the data type of the function's parameter variable? Select one: a. Can't tell from the prototype b. int c. double d. void

c. (double)

When used as parameters, these types of variables allow a function to access the parameter's original argument. Select one: a. reference b. floating-point c. counter d. undeclared e. None of these

a. (reference )

The value in a ________ variable persists between function calls. Select one: a. static local b. local c. counter d. dynamic

a. (static local)

This type of variable is defined inside a function and is not accessible outside the function. Select one: a. global b. reference c. local d. counter e. None of these

c. ( local )

Which of the following statements about global variables is true? Select one: 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. 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. e. All of these are true.

c. (A global variable can have the same name as a variable that is declared locally within a function.)

This statement causes a function to end. Select one: a. end b. terminate c. return d. release e. None of these

c.( return)

The value in this type of local variable persists between function calls. Select one: a. global b. internal c. static d. dynamic e. None of these

c.( static)

Which line in the following program contains the prototype for the showDub function? 3) 4) void showDub (int); 5) 6) int main () 7) { 8) int x=2; 9) 10) showDub(x); 11) cout << x << endl; 12) return 0; 13) } 14) 15) void showDub(int num) 16) { 17) cout << (num*2)<< endl; 18) } Select one: a. 15 b. 6 c. 10 d. 4

d. (4)

A function is executed when it is: Select one: a. defined b. prototyped c. declared d. called e. None of these

d. (called )

A ________ argument is passed to a parameter when the actual argument is left out of the function call. Select one: a. false b. true c. null d. default e. None of these

d. (default)

This is a collection of statements that performs a specific task. Select one: a. infinite loop b. variable c. constant d. function e. None of these

d. (function )

What is the output of the following program? int getValue (int); int main () { int x=2; cout << getValue(x) << endl; return 0; } int getValue(int num) { return num+5; } Select one: a. 2 b. 5 c. "getValue(x)" d. 7

d.( 7)

Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function? Select one: a. void computeValue(int x); b. void computeValue(10); c. computeValue(10) d. computeValue(10);

d.( computeValue(10))

In a function header, you must furnish: Select one: a. data type(s) of the parameters b. data type of the return value c. the name of function d. names of parameter variables e. All of these

e.( All of these )

True/False: A function's return data type must be the same as the function's parameter(s). Select one: True False

f (False )

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. Select one: a. persist b. execute c. communicate d. change e. None of these

a. ( persist)

A ________ variable is declared outside all functions. Select one: a. local b. global c. floating-point d. counter e. None of these

b. ( global )

What is the output of the following program? 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;} Select one: a. 2 0 2 b. 0 0 0 c. 2 2 2 d. 2 0 0

a. ( 2 0 2)

This is a dummy function that is called instead of the actual function it represents. Select one: a. overloaded function b. driver c. stub d. main function

c. (stub )

Which line in the following program contains the header for the showDub function? 3) 4) void showDub (int); 5) 6) int main () 7) { 8) int x=2; 9) 10) showDub(x); 11) cout << x << endl; 12) return 0; 13) } 14) 15) void showDub(int num) 16) { 17) cout << (num*2)<< endl; 18) } Select one: a. 4 b. 10 c. 6 d. 15

d. (15)

Look at the following function prototype. int myFunction(double, double, double) How many parameter variables does this function have? Select one: a. 1 b. 2 c. Can't tell from the prototype d. 3

d. (3)

This function causes a program to terminate, regardless of which function or control mechanism is executing. Select one: a. terminate() b. return() c. continue() d. exit() e. None of these

d. (exit() )


Related study sets

Unit 17 Real Property Valuation REX 7600 RE Pre-Licensing

View Set

Test 4: Immunity, Tissue Integrity, Infection, Perfusion

View Set

Horizontal Integration and Vertical Integration,

View Set

41. Battle of Plassey (23 June 1757)

View Set