Call Stacks
Call Stacks
When you call a function, the system sets aside space in memory for that
function to do its work
- More than one function's stack frame may exist in memory at a given time.
- If main() calls move(), which then calls direction() all three functions have
open frames
- These frames are arranged in a stack. The frame for the most recently
called function is always on the top of the stack
CALL STACK
- When a new function is called, a new frame is pushed onto the top of a
stack and becomes the active frame
- When a function finishes its work or returns, its frame is popped off the
stack
- the frame below it becomes the new active function on the top of the
stack,
- This function picks up where it left off
In recursio
stack and
in which t
onto the n
on each function is piled onto the
d on hold until the base case is reached,
they leave the stack passing the value
next.