Functions – Flashcards

Unlock all answers in this set

Unlock answers
question
This is a collection of statements that performs a specific task. a. infinite loop b. variable c. constant d. function e. None of these
answer
d. function
question
2. A function __________ contains the statements that make up the function. a. definition b. prototype c. call d. expression e. parameter list
answer
a. definition
question
3. A function can have zero to many parameters, and it can return this many values. a. zero to many b. no c. only one d. a maximum of ten e. None of these
answer
c. only one
question
4. A function is executed when it is a. defined b. prototyped c. declared d. called e. None of these
answer
d. called
question
5. In a function header, you must furnish 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
answer
e. All of these
question
6. Functions are ideal for use in menu-driven programs. When a user selects a menu item, the program can ________ the appropriate function. a. call b. prototype c. define d. declare e. None of these
answer
a. call
question
7. 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. local
question
8. The value in this type of local variable persists between function calls. a. global b. internal c. static d. dynamic e. None of these
answer
c. static
question
9. 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. Relational e. None of these
answer
b. Default
question
10. 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. reference
question
11. This statement causes a function to end. a. end b. terminate c. return d. release e. None of these
answer
c. return
question
12. _________ functions may have the same name, as long as their parameter lists are different. a. Only two b. Two or more c. Zero d. Un-prototyped e. None of these
answer
b. Two or more
question
13. This function causes a program to terminate, regardless of which function or control mechanism is executing. a. terminate() b. return() c. continue() d. exit() e. None of these
answer
d. exit()
question
14. 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? (All variables are of type int) x = 1; y = 2; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; a. 1 2 3 b. 1 6 3 c. 3 6 3 d. 1 14 9 e. None of these
answer
b. 1 6 3
question
15. This is a statement that causes a function to execute. a. for loop b. do-while loop c. function prototype d. function call e. None of these
answer
d. function call
question
16. It is a good programming practice to ____________ your functions by writing comments that describe what they do. a. execute b. document c. eliminate d. prototype e. None of these
answer
b. document
question
17. 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. argument, parameter
question
18. Which of the following statements about global variables is 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. 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
answer
c. A global variable can have the same name as a variable that is declared locally within a function.
question
19. 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. prototype
question
20. A ___________ variable is declared outside all functions. a. local b. global c. floating-point d. counter e. None of these
answer
b. global
question
21. 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. persist
question
22. A(n) _________ argument is passed to a parameter when the actual argument is left out of the function call. a. false b. null c. default d. None of these
answer
d. None of these
question
23. If a function does not have a prototype, default arguments may be specified in the function ___________. a. call b. header c. execution d. return type e. None of these
answer
b. header
question
24. 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 e. None of these
answer
b. EXIT_SUCCESS
question
25. The value in a(n) _______ variable persists between function calls. a. dynamic b. local c. counter d. static local
answer
d. static local
question
26. This is a dummy function that is called instead of the actual function it represents. a. main function b. stub c. driver d. overloaded function
answer
b. stub
question
27. What is the output of the following program? #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 2 b. 4 2 c. 2 4 d. 4 4
answer
b. 4 2
question
28. What is the output of the following program? #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. 2 0 2
question
29. What is the output of the following program? #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. 2 0 0
question
30. Which line in the following program contains the prototype for the showDub function? 1 #include 2 using namespace std; 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 } a. 4 b. 6 c. 10 d. 15
answer
a. 4
question
31. Which line in the following program contains the header for the showDub function? 1 #include 2 using namespace std; 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 { 7 cout << (num * 2) << endl; 18 } a. 4 b. 6 c. 10 d. 15
answer
d. 15
question
32. Which line in the following program contains a call to the showDub function? 1 #include 2 using namespace std; 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 } a. 4 b. 6 c. 10 d. 15
answer
c. 10
question
33. Look at the following function prototype. int myFunction(double); What is the data type of the funtion's parameter variable? a. int b. double c. void d. Can't tell from the prototype
answer
b. double
question
34. Look at the following function prototype. int myFunction(double); What is the data type of the funtion's return value? a. int b. double c. void d. Can't tell from the prototype
answer
a. int
question
35. Look at the following function prototype. int myFunction(double, double, double); How many parameter variables does this function have? a. 1 b. 2 c. 3 d. Can't tell from the prototype
answer
c. 3
question
36. What is the output of the following program? #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. 7
question
37. Here is the header for a function named computeValue: void computeValue(int value) Which of the following is a valid call to the function? a. computeValue(10) b. computeValue(10); c. void computeValue(10); d. void computeValue(int x);
answer
b. computeValue(10);
Get an explanation on any task
Get unstuck with the help of our AI assistant in seconds
New