Caffeinated Coder
Book an appointment
Lesson 06 · Memory

Variables on the stack

Every time a function runs, its local variables need somewhere to live. C++ gives each call a stack frame: a block of memory pushed on top of the call stack when the function starts and popped off when it returns. Step through a ten-line program, watch main's frame appear, a call to square push a second frame on top, values get copied in and out, and the frames disappear again, automatically.

10 min10 steps5 questionsIntermediate
Fig 6 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.