Notes

Thoughts, write-ups, and things worth remembering.

Pointer basics

#cpp#pointers Updated Sep 16, 2026

A pointer is a variable that stores a memory address instead of a value.

int x = 5;
int* p = &x;    // &  = "address of" -> p now holds x's address
*p = 10;        // *  = "dereference" -> follow the address, x is now 10
std::cout << p;   // prints the address itself
std::cout << *p;  // prints 10

nullptr — a pointer that points nowhere

int* p = nullptr;
*p = 5;   // crash - dereferencing null is undefined behavior

Always check before dereferencing a pointer you’re not sure about.

References vs pointers
nullptr