Chapter 9 Flashcards
What does the indirection operator do?
It dereferences a pointer, allowing code to work with the value that the pointer points to
What are the 3 different uses for the * operator?
- multiplication operator
- definition of a pointer variable
- the indirection operator
What mathematical operations are allowed on pointers?
Addition and subtraction
Assuming that ptr is a pointer to an int, what happens when you add 4 to ptr?
It adds 4 times the size of an int to the address stored in ptr
What is the purpose of the new operator?
To dynamically allocate memory
What is the purpose of the delete operator?
to free memory that has been dynamically allocated with the new operator
Under what circumstances can you successfully return a pointer from a function?
you should only return a pointer from a function if it is:
- a pointer to an object that was passed into the function as an argument
- a pointer to a dynamically allocated object
Each byte in memory is assigned a unique ______.
Address
The ______ operator can be used to determine a variable’s address
& (ampersand)
_______ variables are designed to hold addresses.
Pointer
The _______ operator can be used to work with the variable a pointer points to.
Indirection ( * )
Array names can be used as ______, and vice versa.
Pointers
Creating variables while a program is running is called.
Dynamic memory allocation
The _____ operator is used to dynamically allocate memory.
new
Under older compilers, if the new operator cannot allocate the amount of memory requested, it returns _____.
null (/zero)
A pointer that contains the address 0 is called a(n) ____ pointer.
null
When a program is finished with a chunk of dynamically allocated memory, it should free it with the _____ operator.
delete
You should only use pointers with delete that were previously used with _____.
new
[T/F]
Each byte of memory is assigned a unique address
true
[T/F]
The * operator is used to get the address of a variable
false
[T/F]
Pointer variables are designed to hold addresses
true
[T/F]
The & symbol is called the indirection operator
false
[T/F]
The & operator dereferences a pointer
false
[T/F]
When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to
true
[T/F]
Array names cannot be dereferenced with the indirection operator
false
[T/F]
When you add a value to a pointer, you are actually adding that number times the size of the data type referenced by the pointer.
true
[T/F]
The address operator is not needed to assign an array’s address to a pointer
true
[T/F]
You can change the address that an array name points to
false
[T/F]
Any mathematical operation, including multiplication and division, may be performed on a pointer
false
[T/F]
Pointers may be compared using the relational operators
true
[T/F]
When used as function parameters, reference variables are much easier to work with than pointers
true
[T/F]
The new operator dynamically allocates memory
true
[T/F]
A pointer variable that has not been initialized is called a null pointer
false
[T/F]
The address 0 is generally considered unusable
true
[T/F]
In using a pointer with the delete operator, it is not necessary for the pointer to have been previously used with the new operatior
false