A pointer is a variable that stores a memory address. Pointers let functions modify caller data, walk through arrays and strings, build dynamic data structures, and call functions indirectly. This section covers address-of (`&`) and **dereference (*), pointer arithmetic, pointers and arrays, strings, function pointers, `void` and `NULL` pointers, and dangling pointers**.
Read declarations from the name outward.
int *p is "p is a pointer to int". int *arr[3] is an array of three pointers, while int (*fp)(int) is a pointer to a function taking an int.
Path
Learning Path
Work through the stages in order, or jump to a topic from the index below (13 tutorials).
A pointer that has not been assigned points to a random address. Initialize to a valid address or NULL.
null
Dereferencing NULL
Reading or writing through NULL crashes. Check before use.
dangle
Using freed memory
After free(p) or after a function returns, old addresses are invalid. Set pointers to NULL when done.
Remember
Key Takeaways
&: address of.
*: value at.
Valid: every pointer should point somewhere valid or be NULL.
One line: A pointer is a variable that stores a memory address.
Frequently Asked Questions
A pointer is a variable whose value is the memory address of another object. You declare it with * and read or write the target with the dereference operator *.
They add a layer of indirection and mistakes cause undefined behavior rather than clear errors. Practice with small programs and compile with warnings and AddressSanitizer.
Typically 8 bytes on 64-bit systems and 4 bytes on 32-bit systems, regardless of the pointed-to type.