Ch 6 Multiple Choice

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

You must always furnish an argument with a function call.

F

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

A

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

A

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

B

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

B

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<<x<<" "<<y<<" " <<z<<endl; a. 123 b. 163 c. 363 d. 1149 e. 2345

B

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

C

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

C

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

C

What will the following code display? #include <iostream> 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

D

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

A

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

A

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

A

A function's return data type must be the same as the function's parameters.

F

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.

A, B, C, E

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

D

A collection of statements that performs a specific task is a(n) a. infinite loop b. variable c. constant d. function e. decision

D

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

D

The value in a ____ variable persists between function calls a. dynamic b. global c. floating-point d. static local e. counter

D

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

D

A parameter is a special purpose variable that is declared inside the parentheses of a function definition.

T

A static variable that is defined within a function is initalized only once, the first time it is called.

T

Global variables are initialized to zero by default.

T

It is not considered good programming practice to declare all your variables globally.

T

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

A, B, C, D

__________ 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

B

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

C

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

B

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

B

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);

B

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

B

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

B

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

B

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

B

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

B

What will the following code display? #include <iostream> 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

B

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

C

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

C

What will the following code display? #include <iostream> 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)

C

Which line in the following program contains the header for the showDub function? 1 #include<iostream> 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

D

A local variable and a global variable may not have the same name within a program.

F

Local variables are initialized to zero by default.

F

When a function is called, flow of control moves to the function's prototype.

F

What will the following code display? #include <iostream> 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

A

Which line in the following program contains the prototype showDub function? 1 #include<iostream> 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

A

It is possible for a function to have some parameters with default arguments and some without.

T

One reason for using functions is to break programs into manageable units or modules.

T

You may use the exit() function to terminate a program, regardless of which control mechanism is executing.

T


Kaugnay na mga set ng pag-aaral

Declaration of Independence Scavenger Hunt

View Set

Abeka English 11 Appendix Quiz GG

View Set

Live Virtual Machine Lab 6.2: Module 06 Troubleshooting and Securing Wireless Networks

View Set