What does the address-of operator `&` produce?
The address-of operator `&` produces a pointer to an object or function, such as `int* p = &score;`.
Study 07 Pointers and Memory Basics with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What does the address-of operator `&` produce?
The address-of operator `&` produces a pointer to an object or function, such as `int* p = &score;`.
What does dereferencing a valid object pointer do?
The dereference operator `*` designates the object pointed to. Reading `*p` accesses it, while assigning to `*p` changes it.
What happens when an invalid pointer is dereferenced?
Dereferencing a null, dangling, uninitialized, or out-of-range pointer is undefined behavior; C++ places no requirements on the result.
How do `const int*` and `int* const` differ?
`const int* p` allows the pointer to change but not the pointed-to `int`; `int* const p` allows the `int` to change but not the pointer.
What value does an uninitialized pointer contain?
An uninitialized pointer contains an indeterminate value. It should be initialized before use, commonly to `nullptr` when it has no target.
Why is `nullptr` preferred for null pointers?
`nullptr` represents a null pointer value and has type `std::nullptr_t`. It is preferred to `0` and `NULL` for expressing pointer intent.
What does adding `1` to a pointer advance?
For an array pointer, adding `1` advances by one element of the pointed-to type, not by one byte.
May a one-past-the-end pointer be dereferenced?
A one-past-the-end pointer may be formed and used as a boundary marker, but it must not be dereferenced.
What conversion usually occurs when an array is used in an expression?
In most expressions, an array converts to a pointer to its first element. The array and pointer remain different types.
How is the array subscript `a[b]` defined?
`a[b]` means, in effect, `*(a + b)`. Therefore `values[2]` and `*(values + 2)` access the same element.
Does an array parameter preserve the array's length?
In a function parameter list, `int values[]` is adjusted to mean `int* values`; it does not convey the array length.
How can a pointer parameter modify the caller's object?
A function receives a copy of the pointer, but modifying `*value` changes the caller's object because both pointers designate that object.