Flashcards in Chapter 9 Deck (35)
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?
1. multiplication operator
2. definition of a pointer variable
3. 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 ______.
The ______ operator can be used to determine a variable's address
_______ variables are designed to hold addresses.
The _______ operator can be used to work with the variable a pointer points to.
Indirection ( * )
Array names can be used as ______, and vice versa.
Creating variables while a program is running is called.
Dynamic memory allocation
The _____ operator is used to dynamically allocate memory.
Under older compilers, if the new operator cannot allocate the amount of memory requested, it returns _____.
A pointer that contains the address 0 is called a(n) ____ pointer.
When a program is finished with a chunk of dynamically allocated memory, it should free it with the _____ operator.
You should only use pointers with delete that were previously used with _____.
Each byte of memory is assigned a unique address
The * operator is used to get the address of a variable
Pointer variables are designed to hold addresses
The & symbol is called the indirection operator
The & operator dereferences a pointer
When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to
Array names cannot be dereferenced with the indirection operator
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.
The address operator is not needed to assign an array's address to a pointer
You can change the address that an array name points to
Any mathematical operation, including multiplication and division, may be performed on a pointer