c4 Flashcards
(15 cards)
What does the indirection operator do?
Accesses the value stored at a memory address.
What will *arr display?
The first element of the array arr.
What will *arr + 2 display?
The first element plus 2.
What are three uses of the & operator?
Address-of, reference declaration, bitwise AND.
What math operations are allowed on pointers?
Addition and subtraction.
What happens when you add 4 to a pointer?
It moves forward 4 elements.
What does cout «_space;*(numbers + 2) display?
The value at numbers[2].
What is the purpose of the new operator?
Dynamically allocates memory.
What happens if new cannot allocate memory?
Returns a null pointer (0 or nullptr).
How did older compilers handle memory allocation failure?
Returned a null pointer (0).
What is the purpose of the delete operator?
Releases dynamically allocated memory.
When can you return a pointer from a function?
When it points to valid memory like dynamic memory.
What is a pointer to a constant?
Pointer cannot modify the value it points to.
What is a constant pointer?
Pointer cannot point to a different address.
Two advantages of const pointer parameters?
Protects data from changes; allows use with const arguments.