Learn/C++ Fundamentals & Execution Tracing/Pointers, Addresses, and Dereferencing
C++ 15 min 1 Questions

Pointers, Addresses, and Dereferencing

Memory Models: Pointers and Dereferencing

A pointer in C++ is a variable that stores the memory address of another variable.

#### Fundamentals:

  • Address-of operator (&): Retrieves the physical memory address of an object.
  • Dereference operator (*): Reads or writes the value stored at that address.
  • cpp
    int value = 42;
    int* ptr = &value; // ptr stores address of value
    *ptr = 99;         // Modifies value through ptr

    #### Common Pitfalls:

  • Dereferencing uninitialized or nullptr pointers causes segmentation faults.
  • Pointer arithmetic advances by sizeof(*ptr) bytes, not single bytes.
  • Practice & Output Prediction

    Verify your understanding of this lesson. Answers are validated server-side.

    Question 1 of 1 • 10 ptsoutput prediction

    What will this C++ code output to the terminal?

    Note: Output verification is whitespace-tolerant.