# College Computing Chapter 9 Quiz

## Unlock all answers in this set

question
What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl;
2
question
Look at the following statement: sum += *array++; This statement...
assigns the dereferenced pointer's value, then increments the pointer's address
question
Dynamic memory allocation occurs
when a new variable is created at runtime
question
These can be used as pointers....
Array names
question
Which of the following statements deletes memory that has been dynamically allocated for an array?
delete [] array;
question
True/False: With pointer variables you can access, but you cannot modify, data in other
False
question
A pointer may be initialized with
the address of an existing object
question
Which of the following statements is not valid C++ code?
All of these are invalid
question
What will the following statement output? cout << &num1;
The memory address of the variable called num1.
question
What does the following statement do? double *num2;
Declares a pointer variable named num2.
question
True/False: A pointer with the value 0 (zero) is called a NULL pointer.
True
question
The statement cin >> *num3;
stores the keyboard input into the variable pointed to by num3.
question
A pointer variable is designed to store
question
Use the delete operator only on pointers that were
created with the new operator
question
A pointer variable may be initialized with
any address in the computer's memory
question
The statement int *ptr = new int;
assigns an address to the variable named ptr.
question
Look at the following code. int numbers[] = {0, 1, 2, 3, 4 }; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true?
ptr will hold the address of numbers[1]
question
Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or __________ a pointer.
multiply, divide
question
The contents of pointer variables may be changed with mathematical statements that perform:
question
When you work with a dereferenced pointer, you are actually working with:
the actual value of the variable whose address is stored in the pointer variable
question
Look at the following statement. int *ptr; In this statement, what does the word int mean?
ptr is a pointer variable that will store the address of an integer variable
question
Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;
the value stored in the variable whose address is contained in ptr
question
Assuming myValues is an array of int values, and index is an int variable, both of the following statements do the same thing. cout << myValues[index] << endl; cout << *(myValues + index) << endl; (T,F)
True
question
Which statement displays the address of the variable num1?
cout << &num1
question
When this is placed in front of a variable name, it returns the address of that variable.
ampersand ( & )
question
The statement int *ptr; has the same meaning as
int* ptr;
question
The _________ , also known as the address operator, returns the memory address of a variable.
ampersand ( & )
question
The ______ and _______ operators can be used to increment or decrement a pointer variable.
++, --
question
True/False: It is legal to subtract a pointer variable from another pointer variable.
True
question
True/False: A pointer can be used as a function argument, giving the function access to the original argument.
True
question
True/False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.
True
question
When using the new operator with an older compiler, it is good practice to:
test the pointer for the NULL address
question
A function may return a pointer, but the programmer must ensure that the pointer
still points to a valid object after the function ends
question
If a variable uses more than one byte of memory, for pointer purposes its address is:
the address of the first byte of storage.
question
True/False: An array name is a pointer constant because the address stored in it cannot be changed during runtime.
True
question
When the less than ( < ) operator is used between two pointer variables, the expression is testing whether
the address of the first variable comes before the address of the second variable in the computer's memory
question
What will the following code output? int number = 22; int *var = &number; cout << var << endl;