Learn C
#include "pointersmemory/pointers_basics.h"

Pointers Basics in C

#concept

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.

#how it works
1

& takes, * follows

&x is x's address; if p holds it, *p is x itself. & and * are inverse operations across the declaration/use divide.

2

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.

3

NULL, always initialized

Pointers start as garbage like ints do — int *p = NULL; marks empty explicitly and crashes loudly (not silently) if misused.

4

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.

#example
#include <stdio.h>
 
int main(void) {
int x = 10;
int *p = &x;
*p = 20;
printf("%d, %d\n", x, *p);
return 0;
}
Output
20, 20
1&x captures x's address into p — p now points at x's memory slot.
2*p = 20 writes through the pointer, changing x itself to 20.
3Both x and *p read 20 because they name the same storage two ways.
#use cases
Dynamic structures (linked lists, trees) where nodes point at each other
Out-parameters and nullable handles via NULL conventions
Modifying caller variables through pointer parameters
Interfacing with OS APIs that speak exclusively in pointers

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself — building beats watching.