| | | | | |

Pointer Dereference

  • To "dereference" a pointer is to access the contents of the memory address that is the pointer's value
  • If p is a pointer, *p is the dereference of p
  • Thus * is a unary operator
  • int* nptr;             // declares nptr (static)
    nptr = new int;        // assigns an int address to nptr (dynamic)
    *nptr = 3;             // stores the value 3 at the address nptr
    std::cout << *nptr;    // output is the contents of the address nptr, i.e., "3"
    std::cout << nptr;     // output is the (hex) address assigned to nptr
    

| | Top of Page | 5. C/C++ Pointers, Arrays, and Pointer Arithmetic - 3 of 17