Call Stack: 27 MCQs with answers
All 27 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 17 questions
Q1. What is the primary role of the stack in function calling?
BeginnerShow answer & explanation
To manage function calls and local variables
The stack is used to manage function calls, including storing return addresses, parameters, and local variables.
Q2. When a function is called, what is typically pushed onto the stack?
BeginnerShow answer & explanation
Return address and parameters
Upon a function call, the return address and parameters are pushed onto the stack to allow the function to execute and return properly.
Q3. What happens to the stack when a function returns?
BeginnerShow answer & explanation
The stack frame is popped
When a function returns, its stack frame is popped off the stack, and control returns to the caller.
Q4. What is the LIFO principle?
BeginnerShow answer & explanation
Last In First Out
LIFO stands for Last In First Out, which is the order in which items are added and removed from a stack.
Q5. Why is the stack called a 'call stack'?
BeginnerShow answer & explanation
Because it stores function call information
The stack is often called the call stack because it manages the sequence of function calls.
Q6. Which data structure is most suitable for implementing function calls?
BeginnerShow answer & explanation
Stack
A stack is ideal because function calls follow a last-in-first-out order.
Q7. A stack frame is created for every function call.
BeginnerShow answer & explanation
True
Each function call typically creates a new stack frame to hold its execution context.
Q8. What is the purpose of the call stack in a program?
BeginnerShow answer & explanation
To keep track of function calls and returns
The call stack keeps track of who called whom, what arguments were passed, and where to return, making it essential for function execution.
Q9. What is typically stored in a stack frame?
BeginnerShow answer & explanation
Function parameters and local variables
A stack frame holds the function's parameters, local variables, the return address, and saved registers.
Q10. What does LIFO stand for in the context of the stack?
BeginnerShow answer & explanation
Last In, First Out
LIFO stands for Last In, First Out, which describes how the stack operates by returning functions in the reverse order they were called.
Q11. What happens to the stack when a function returns?
BeginnerShow answer & explanation
The stack frame for that function is popped off
When a function returns, its stack frame is popped off, which removes the function's parameters and local variables from the stack.
Q12. What is a stack overflow?
BeginnerShow answer & explanation
When too many frames are pushed onto the stack
A stack overflow occurs when too many frames are pushed onto the stack, often due to infinite or very deep recursion.
Q13. Why is the return address important in a stack frame?
BeginnerShow answer & explanation
It indicates where to return after the function finishes
The return address is crucial because it tells the program where to return after the callee function has finished executing.
Q14. What is the typical use of the stack in programming?
BeginnerShow answer & explanation
For storing short-lived function call data
The stack is used for short-lived call bookkeeping, such as storing parameters and local variables during function execution.
Q15. How does recursion utilize the stack?
BeginnerShow answer & explanation
Each recursive call pushes a new frame onto the stack
In recursion, each recursive call pushes a new stack frame, allowing the program to keep track of multiple calls.
Q16. What is a common mistake that can lead to a stack overflow?
BeginnerShow answer & explanation
Not having a base case in recursive functions
A common mistake that leads to stack overflow is failing to provide a base case in recursive functions, causing infinite recursion.
Q17. What does a debugger display when a program crashes?
BeginnerShow answer & explanation
The call stack of active function calls
When a program crashes, a debugger can display the call stack, which shows the chain of active function calls leading to the crash.
Building up · 10 questions
Q18. What is a stack frame?
IntermediateShow answer & explanation
A region of the stack containing function call information
A stack frame is the portion of the stack that holds the parameters, return address, and local variables for a single function call.
Q19. Why is the stack useful for function calls?
IntermediateShow answer & explanation
It supports recursion and nested calls
The stack's LIFO nature makes it ideal for managing nested function calls and recursion.
Q20. What is the order of operations when a function is called?
IntermediateShow answer & explanation
Push parameters, push return address, jump to function
Typically, parameters are pushed first, then the return address, and then control jumps to the function.
Q21. What is the stack pointer used for?
IntermediateShow answer & explanation
To point to the top of the stack
The stack pointer keeps track of the top of the stack, which changes as items are pushed or popped.
Q22. What is a stack overflow?
IntermediateShow answer & explanation
When the stack exceeds its allocated size
A stack overflow occurs when too many items are pushed onto the stack, exceeding its capacity, often due to infinite recursion.
Q23. How does the stack support recursion?
IntermediateShow answer & explanation
By storing multiple return addresses and local variables
Each recursive call creates a new stack frame, allowing the function to maintain separate local variables and return addresses.
Q24. Which of the following is NOT typically stored in a stack frame?
IntermediateShow answer & explanation
Global variables
Global variables are stored in a separate data segment, not in the stack frame.
Q25. What is the effect of popping a stack frame?
IntermediateShow answer & explanation
It removes the top function's data and returns control
Popping a stack frame removes the top function's data and restores control to the calling function.
Q26. What happens if a function is called but never returns?
IntermediateShow answer & explanation
The stack frame remains, potentially causing a stack overflow
If a function never returns, its stack frame is not popped, leading to accumulation and possibly a stack overflow.
Q27. The stack grows upwards in memory on all computer architectures.
IntermediateShow answer & explanation
False
The direction of stack growth depends on the architecture; it can grow upwards or downwards.
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