Base CS from zero
Functions and the call stack: free-recall review
Retrieval beats re-reading. For each prompt, say or write a full answer from memory before you open the model answer — the effort of pulling the mechanism out of your head is what makes it stick.
Reconstruct the unit’s spine from memory — what a function is at the machine level, what a stack frame holds, how parameters and return values cross the boundary, why scope and lifetime end with the frame, and what recursion does to the stack.
- 01What is a function at the machine level, and what exactly does a CALL instruction do?
- 02What does a stack frame contain, and when is it pushed and popped?
- 03Why is the call stack LIFO, and what does that imply about which frame finishes first?
- 04How do parameters get into a function and how does a return value get out, and why is pass-by-value safe?
- 05What is the difference between a local variable's scope and its lifetime, and what happens to it when the function returns?
- 06What is recursion in terms of the stack, what are its two parts, and what causes a stack overflow?
If you could reconstruct each answer from memory, you hold the unit’s spine: a function is a labelled address, CALL saves a return address and jumps, each call pushes a LIFO frame of return-address-plus-locals, parameters copy in and a return value comes back out across that boundary, a local’s scope and lifetime end when its frame pops, and recursion is the same frame-push repeated — bounded only by a reachable base case before the stack overflows.