Chapter 9 C++
12) A function may return a pointer, but the programmer must ensure that the pointer ________. A) still points to a valid object after the function ends B) has not been assigned an address C) was received as a parameter by the function D) has not previously been returned by another function E) None of these
A
5) ________ can be used as pointers. A) Array names B) Numeric constants C) Punctuation marks D) All of these E) None of these
A
7) In C++ 11, the ________ key word was introduced to represent the address 0. A) nullptr B) NULL C) weak_ptr D) All of these E) None of these
A
1) The ________, also known as the address operator, returns the memory address of a variable. A) asterisk ( * ) B) ampersand ( & ) C) percent sign (%) D) exclamation point ( ! ) E) None of these
B
10) Look at the following statement: sum += *array++; This statement ________. A) is illegal in C++ B) will always result in a compiler error C) assigns the dereferenced pointer's value, then increments the pointer's address D) increments the dereferenced pointer's value by one, then assigns that value E) None of these
C
11) Use the delete operator only on pointers that were ________. A) never used B) not correctly initialized C) created with the new operator D) dereferenced inappropriately E) None of these
C
14) Which of the following statements deletes memory that has been dynamically allocated for an array? A) int array = delete memory; B) int delete[ ]; C) delete [] array; D) new array = delete; E) None of these
C
15) When this is placed in front of a variable name, it returns the address of that variable. A) asterisk ( * ) B) conditional operator C) ampersand ( & ) D) semicolon ( ; ) E) None of these
C
2) With pointer variables, you can ________ manipulate data stored in other variables. A) never B) seldom C) indirectly D) All of these E) None of these
C
4) When you work with a dereferenced pointer, you are actually working with ________. A) a variable whose memory has been allocated B) a copy of the value pointed to by the pointer variable C) the actual value of the variable whose address is stored in the pointer variable D) All of these E) None of these
C
6) The contents of pointer variables may be changed with mathematical statements that perform ________. A) all mathematical operations that are legal in C++ B) multiplication and division C) addition and subtraction D) B and C E) None of these
C
9) When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________. A) the value pointed to by the first is less than the value pointed to by the second B) the value pointed to by the first is greater than the value pointed to by the second C) the address of the first variable comes before the address of the second variable in the computer's memory D) the first variable was declared before the second variable E) None of these
C
3) The statement: int *ptr = nullptr; has the same meaning as ________. A) int ptr = nullptr; B) *int ptr = nullptr; C) int ptr* = nullptr; D) int* ptr = nullptr; E) None of these
D
8) What does the following statement do? double *num2; A) Declares a double variable named num2. B) Declares and initializes an pointer variable named num2. C) Initializes a variable named *num2. D) Declares a pointer variable named num2. E) None of these
D
13) Which of the following statements is not valid C++ code? A) int ptr = &num1; B) int ptr = int *num1; C) float num1 = &ptr2; D) All of these are valid. E) All of these are invalid.
E