Interactive
Memory, visualized
The whole reason C-lingua exists is that these languages make you think about memory. So here it is, moving: watch struct padding appear and vanish as you reorder fields, step a heap block through malloc to free to a use-after-free that lights up red, and see the call stack grow, shrink, and dangle. All computed in your browser, no code executed.
struct fields (drag order with the arrows)
add:
0
sizeof
0
data bytes
0
wasted (padding)
0
alignof
padding (wasted)
Each cell is one byte. Reorder fields largest-first to squeeze the holes out.
Stack
Heap
A dangling pointer is a pointer that outlives the thing it points at. Reading through one is undefined behavior - the block may be reused at any moment.
Call stack (grows downward)
Returning the address of a local is the stack's version of a use-after-free: the frame is popped the instant the function returns, so the pointer aims at reclaimed space.