Skip to content

Latest commit

 

History

History
25 lines (21 loc) · 1.12 KB

pointer_basics.md

File metadata and controls

25 lines (21 loc) · 1.12 KB

Pointer Basics

A pointer is a type that stores the address of an object. For example, int* is a pointer to an int, and will store the address of an int.

  • the address-of operator & creates a pointer to an object
  • the indirection operator * accesses the pointed-to object

Using these operators is called referencing and dereferencing, respectively.

int x = 50;
int* p = &x; // p ==   &x, *p == 50, x == 50
*p = 10;     // p ==   &x, *p == 10, x == 10
p = NULL;    // p == NULL, *p == ??, x == 10

Note: use nullptr instead of NULL in C++

See Also

?creditFooter 164892896514801664