Functions

Ace your homework & exams now with Quizwiz!

28. What is the output of the following program? #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. 2 0 2

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

a. 4

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

a. call

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

a. definition

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

b. 1 6 3

27. What is the output of the following program? #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 2 b. 4 2 c. 2 4 d. 4 4

b. 4 2

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

b. Default

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

b. EXIT_SUCCESS

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

b. Two or more

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

b. computeValue(10);

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

b. document

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

b. double

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

b. prototype

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

b. stub

32. Which line in the following program contains a call to the showDub function? 1 #include <iostream> 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

c. 10

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

c. 3

36. What is the output of the following program? #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. 7

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

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

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

c. argument, parameter

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

c. local

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

c. only one

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

c. return

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

d. 15

29. What is the output of the following program? #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. 2 0 0

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

d. None of these

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

d. exit()

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

d. function

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

d. function call

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

a. int

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

a. persist

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

a. reference

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

d. called

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

b. global

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

b. header

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

c. static

25. The value in a(n) _______ variable persists between function calls. a. dynamic b. local c. counter d. static local

d. static local

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

e. All of these


Related study sets

sports med chapter 1 study guide

View Set

AP Human Geography Final Exam Review

View Set

Ch. 20- Freak the Mighty Strikes Again

View Set

Chapter 35: Employment Discrimination

View Set

Social/Behavioral Research: Module 8

View Set

Crime and Punishment - characterization

View Set

ilustreous-gre-barrons-hi-freq-plus

View Set