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)