Pointers Basics in C
A pointer is a variable holding a memory address: int *p = &x; stores x's address in p, *p reads or writes x through it, and & takes addresses. This indirection powers dynamic allocation, data structures built from linked nodes, and callbacks — plus the entire operating-system interface.
The discipline is non-negotiable: initialize every pointer (NULL when targetless), check for NULL before dereferencing, and never use a pointer after its pointee dies. In C there are no references or smart pointers to fall back on — raw pointer mechanics are the whole game.
& takes, * follows
&x is x's address; if p holds it, *p is x itself. & and * are inverse operations across the declaration/use divide.
Declare carefully
int *p reads as pointer-to-int. Write int *p and declare one pointer per line — int *a, b makes b a plain int.
NULL, always initialized
Pointers start as garbage like ints do — int *p = NULL; marks empty explicitly and crashes loudly (not silently) if misused.
Never dangle
A pointer to a dead local or freed block is a time bomb. Null it, reassign it, or scope it — never dereference the dead.
#include <stdio.h> int main(void) { int x = 10; int *p = &x; *p = 20; printf("%d, %d\n", x, *p); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.