Free Online Flashcard Deck

07 Pointers and Memory Basics Free Online FlashCards

Study 07 Pointers and Memory Basics with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What does the address-of operator `&` produce?

Back

The address-of operator `&` produces a pointer to an object or function, such as `int* p = &score;`.

02
Front

What does dereferencing a valid object pointer do?

Back

The dereference operator `*` designates the object pointed to. Reading `*p` accesses it, while assigning to `*p` changes it.

03
Front

What happens when an invalid pointer is dereferenced?

Back

Dereferencing a null, dangling, uninitialized, or out-of-range pointer is undefined behavior; C++ places no requirements on the result.

04
Front

How do `const int*` and `int* const` differ?

Back

`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.

05
Front

What value does an uninitialized pointer contain?

Back

An uninitialized pointer contains an indeterminate value. It should be initialized before use, commonly to `nullptr` when it has no target.

06
Front

Why is `nullptr` preferred for null pointers?

Back

`nullptr` represents a null pointer value and has type `std::nullptr_t`. It is preferred to `0` and `NULL` for expressing pointer intent.

07
Front

What does adding `1` to a pointer advance?

Back

For an array pointer, adding `1` advances by one element of the pointed-to type, not by one byte.

08
Front

May a one-past-the-end pointer be dereferenced?

Back

A one-past-the-end pointer may be formed and used as a boundary marker, but it must not be dereferenced.

09
Front

What conversion usually occurs when an array is used in an expression?

Back

In most expressions, an array converts to a pointer to its first element. The array and pointer remain different types.

10
Front

How is the array subscript `a[b]` defined?

Back

`a[b]` means, in effect, `*(a + b)`. Therefore `values[2]` and `*(values + 2)` access the same element.

11
Front

Does an array parameter preserve the array's length?

Back

In a function parameter list, `int values[]` is adjusted to mean `int* values`; it does not convey the array length.

12
Front

How can a pointer parameter modify the caller's object?

Back

A function receives a copy of the pointer, but modifying `*value` changes the caller's object because both pointers designate that object.