What does a pointer store?
A pointer is an object that stores an address, allowing indirect access to another object or function.
Study 7 Pointers and Dynamic Memory with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What does a pointer store?
A pointer is an object that stores an address, allowing indirect access to another object or function.
What does the `&` operator produce?
The address-of operator `&` produces a pointer to an object, such as `int* address = &score;`.
What does unary `*` do to a pointer?
The unary `*` operator dereferences a pointer, accessing its target. It can read the target or modify it when the pointer permits modification.
When is pointer dereferencing valid?
Dereferencing is valid only when the pointer points to a live object or function. Null, dangling, uninitialized, and otherwise invalid pointers must not be dereferenced.
How does pointer arithmetic scale movement?
Within an array, `p + 1` advances to the next element, not necessarily the next byte. The step is scaled by the pointed-to type.
Where is array pointer arithmetic defined?
Pointer arithmetic is defined within one array, including the position one past its end. A one-past pointer may be formed but must not be dereferenced.
What does subtracting same-array pointers produce?
Subtracting two pointers into the same array gives the number of elements between them, such as `&numbers[4] - &numbers[0]`, which equals 4.
What does an array name usually convert to?
In most expressions, an array name converts to a pointer to its first element, so `values` is equivalent to `&values[0]` in that context.
How do arrays and pointers differ?
An array owns a fixed number of elements and includes its size in its type; a pointer only stores an address and does not remember the element count.
What does `nullptr` represent?
`nullptr` represents a pointer that points to no object or function. It may be compared, copied, or assigned, but it must not be dereferenced.
What is a dangling pointer?
A dangling pointer refers to an object whose lifetime has ended. Returning the address of a local variable creates this problem after the function returns.
Which deletion matches `new` and `new[]`?
A single object allocated with `new` must be released with `delete`; an array allocated with `new[]` must be released with `delete[]`.