A pointer variable can store ________.
integer values
double values
addresses of other variables
string values
In order to determine the address of a variable in C++, we can use the ________ operator.
@
++
*
&
Pointer variables must always be ________ before they are used.
dereferenced
static
initialized
checked
In order to follow a pointer and access the data that it is pointing to, we must ________ the pointer using the ________ operator.
use, @
access, &
dereference, *
reference, *
Pointers can be used to dynamically allocate storage from the ________ at ________.
stack, compile-time
stack, run-time
heap or free store, run-time
heap or free store, compile-time
When using raw pointers and dynamic storage allocation, we must always de-allocate the used storage by using ________ to prevent ________.
delete, memory leaks
free, buffer overruns
delete, stack overflows
new, memory leaks
________ and pointers can be used interchangeably in many contexts.
Function calls
Classes
Vectors
Array names
What types of variables can ptr store given the following declaration below?
int **ptr;
integers
addresses of integers
addresses of pointers to integers
any type of integer
What does the following code snippet display?
int *data = new int[5]; for (int i = 0; i<5; i++) *(data + i) = i*2; for (int i = 0; i<=4; i++) cout << data[i] << " " ; cout << endl; delete [] data;
0 1 2 3 4
0 2 4 6 8
2 4 6 8 10
garbage data
Given the following pointer declarations, what can you say about ptr1 and ptr2?
int *ptr1; int *ptr2 { nullptr};
ptr1 and ptr2 are both contain the address 0
ptr1 and ptr2 are both initialized
ptr1 is uninitialized and ptr2 is initialized
ptr1 and ptr2 are both uninitialized