Call Stack: 17 flashcards
All 17 flashcards from this kit, free and with no sign-up.
1. What is the **call stack**?
Show the answer
A **LIFO (Last-In, First-Out)** data structure used by the runtime to manage function calls, storing an **activation record (stack frame)** for each active call.
2. What is a **stack frame** (activation record)?
Show the answer
The block of memory pushed for one function call. It typically holds **parameters, local variables, the return address, and saved registers**.
3. What happens on the stack when a function is **called**?
Show the answer
A new **stack frame** is **pushed** onto the top of the call stack, and control transfers to the called function.
4. What happens on the stack when a function **returns**?
Show the answer
Its **stack frame is popped** off the top, control returns to the **return address**, and execution resumes in the caller.
5. Why is the call stack called **LIFO**?
Show the answer
Because the **most recently called** function is the **first one to return** — calls are nested, so they unwind in reverse order.
6. What is the **return address** in a stack frame?
Show the answer
The location in the **caller's code** where execution must resume **after** the called function finishes.
7. Trace the stack for: `main` calls `A`, `A` calls `B`.
Show the answer
Stack grows **bottom → top**: `main` → `A` → `B`. When `B` returns, it pops; then `A` returns and pops; finally `main` resumes.
8. What is **recursion** in terms of the call stack?
Show the answer
A function **calling itself**; each recursive call **pushes a new frame**, so the stack grows with recursion depth.
9. What causes a **stack overflow**?
Show the answer
**Too many frames** pushed without returning (e.g., infinite or very deep recursion), exceeding the stack's fixed memory limit.
10. What is the **base case** in recursion and why is it needed?
Show the answer
The condition that **stops further recursive calls**. Without it, frames keep piling up → **stack overflow**.
11. How does the stack support **nested function calls**?
Show the answer
Each nested call gets its **own frame** on top of the previous one, so the runtime can **pause** the caller and **resume** it correctly after the inner call returns.
12. Why can't a simple variable hold the state of multiple active calls?
Show the answer
Because calls are **nested and overlapping** — each active call needs its **own copy** of parameters and locals. The stack provides **one frame per call**.
13. What is the **usefulness** of the call stack for debugging?
Show the answer
It gives a **stack trace (call stack trace)** — the chain of active calls at the point of error — helping locate **where** and **how** the program reached that state.
14. Apply: `main` → `f` → `g` → `h`. Which function returns **first**?
Show the answer
**`h`** returns first (it's on top). Then `g`, then `f`, then `main` — reverse order of calls.
15. Apply: A recursive function has no base case. What happens on the stack?
Show the answer
Frames are **pushed indefinitely** (until memory limit), causing a **stack overflow** and program crash.
16. How does the stack handle **local variables** of different calls to the same function?
Show the answer
Each call gets a **separate frame**, so each call's local variables are **independent** — changing one call's local does not affect another's.
17. Summarize the **flow** of a function call using the stack in 4 steps.
Show the answer
1) **Push** new frame. 2) **Execute** function body. 3) **Pop** frame on return. 4) **Resume** caller at return address.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages