CMPSC11 Final (Study Guide) Fall 11 Prof Hartman Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) This is a collection of statements that performs a specific task. 1) A) function B) constant C) variable D) infinite loop ) A function contains the statements that make up the function. ) A) expression B) definition C) call D) parameter list E) prototype 3) A function can have zero to many parameters, and it can return this many values. 3) A) only one B) no C) zero to many D) a maximum of ten ) In a function header, you must furnish: ) A) data type of the return value B) the name of function C) names of parameter variables D) data type(s) of the parameters E) All of these 1
5) What is the output of the following program? 5) # include <iostream> using namespace std; void dosomething(int&); int main( ) int x = ; dosomething(x); return ; void dosomething(int& num) num = ; cout << num << endl; A) B) C) D) 6) Look at the following function prototype. 6) int myfunction(double); What is the data type of the funtion's parameter variable? A) double B) void C) int D) can't tell from the prototype 7) Which of the following is a valid C++ array definition? 7) A) int array[1]; B) void numbers[5]; C) float $payments[1]; D) int array[]; 8) What is the last legal subscript that can be used with the following array? 8) int values[5]; A) 5 B) 6 C) D)
9) What will the following code display? 9) int numbers[ ] = 99, 87, 66, 55, 11 ; for (int i = 1; i < ; i++) cout << numbers[i] << endl; A) 99 87 66 55 11 C) 87 66 55 11 B) 87 66 55 D) Nothing. This code has an error. 1) A algorithm is a method of locating a specific item of information in a larger collection of data. A) sort B) standard C) linear D) search 11) What will the following code display? 1) 11) int numbers[ ] = 99, 87, 66, 55, 11 ; cout << numbers[3] << endl; A) 66 B) 87 C) 55 D) 11 1) A(n) search is more efficient than a(n) search 1) A) binary, linear B) character, string C) integer, double D) linear, binary 13) A binary search begins with the element of an array. 13) A) first B) largest C) last D) middle 3
1) What is the output of the following code segment? 1) n = 1; for ( ; n <= 5; ) cout << n << ' '; n++; A) 1 3 B) 1 3 5 C) 1 1 1... and on forever D) 3 5 6 E) 3 5 15) What will the following loop display? 15) int x = ; while (x < 5) x++; A) 1 3 B) 1 3 5 C) 1 3 D) The loop will display numbers starting at, for infinity. 16) What will the following code display? 16) int x = ; for (int count = ; count < 3; count++) x += count; A) 6 B) C) 1 D) 3
17) How many times will the following loop display "Hello"? 17) for (int i = ; i > ; i--) cout << "Hello!" << endl; A) 19 B) 1 C) D) an infinite number of times 18) The statement int *ptr = new int; 18) A) assigns an integer less than 3767 to the variable named ptr B) creates a new pointer named int C) assigns an address to the variable named ptr D) results in a compiler error 19) Every byte in the computer's memory is assigned a unique: 19) A) address B) pointer C) dynamic allocation D) name ) What will the following code output? ) int number = ; int *var = &number; cout << *var << endl; A) an asterisk followed by B) an asterisk followed by the address of the number variable C) the address of the number variable D) 1) What will the following code output? 1) int number = ; int *var = &number; cout << var << endl; A) the address of the number variable B) C) an asterisk followed by the address of the number variable D) an asterisk followed by 5
) Look at the following code. ) int numbers[ ] =, 1,, 3, ; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true? A) ptr will hold the address of numbers[] B) ptr will hold the address of numbers[1] C) ptr will hold the address of the nd byte within the element numbers[] D) This code will not compile. 3) When this is placed in front of a variable name, it returns the address of that variable. 3) A) conditional operator B) ampersand ( & ) C) semicolon ( ; ) D) asterisk ( * ) ) What does the following statement do? ) double *num; A) declares a double variable named num B) initializes a variable named *num C) declares and initializes an pointer variable named num D) declares a pointer variable named num 5) These can be used as pointers. 5) A) Array names B) Punctuation marks C) Numeric constants D) All of these 6) The, also known as the address operator, returns the memory address of a variable. 6) A) ampersand ( & ) B) percent sign (%) C) asterisk ( * ) D) exclamation point (! ) 7) algorithms are used to arrange random data into some order. 7) A) Linear B) Sorting C) Standard search D) Binary search 6
8) What will the following code do? 8) const int SIZE = 5; double x[size]; for(int i = ; i <= SIZE; i++) x[i] =.; A) Each element in the array, except the first, is initialized to.. B) Each element in the array is initialized to.. C) Each element in the array, except the first and the last, is initialized to.. D) An error will occur when the code runs. 9) What is the output of the following program? 9) # include <iostream> using namespace std; int getvalue(int); int main( ) int x = ; cout << getvalue(x) << endl; return ; int getvalue(int num) return num + 5; A) 7 B) C) 5 D) "getvalue(x)" 7
3) Which line in the following program contains the prototype for the showdub function? 3) 1 # include <iostream> using namespace std; 3 void showdub(int); 5 6 int main( ) 7 8 int x = ; 9 1 showdub(x); 11 1 return ; 13 1 15 void showdub(int num) 16 17 cout << (num * ) << endl; 18 A) 1 B) C) 15 D) 6 31) What is the output of the following program? 31) # include <iostream> using namespace std; void dosomething(int); int main( ) int x = ; dosomething(x); return ; void dosomething(int num) num = ; cout << num << endl; A) B) C) D) 8
3) What is the output of the following program? 3) # include <iostream> using namespace std; void showdub(int); int main( ) int x = ; showdub(x); return ; void showdub(int num) cout << (num * ) << endl; A) B) C) D) 33) Given the following function definition 33) void calc (int a, int& b) int c; c = a + ; 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 = ; z = 3; calc(x, y); cout << x << " " << y << " " << z << endl; A) 1 1 9 B) 1 6 3 C) 3 6 3 D) 1 3 9