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?

Beginner
A To handle input/output operations B To store global variables C To execute arithmetic operations D To manage function calls and local variables
Show 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?

Beginner
A Return address and parameters B The entire program C Only the function's code D Global variables
Show 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?

Beginner
A The stack frame is pushed B The stack remains unchanged C The stack is cleared entirely D The stack frame is popped
Show 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?

Beginner
A First In Last Out B First In First Out C Last In Last Out D Last In First Out
Show 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'?

Beginner
A Because it is a type of queue B Because it calls functions C Because it is used for arithmetic D Because it stores function call information
Show 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?

Beginner
A Queue B Stack C Array D Linked list
Show 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.

Beginner
A True B False
Show 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?

Beginner
A To keep track of function calls and returns B To execute the main function C To store global variables D To manage memory allocation
Show 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?

Beginner
A Global variables B Static variables C Function parameters and local variables D Heap memory addresses
Show 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?

Beginner
A Last In, First Over B Last In, First Out C Last In, First Option D Last In, First Off
Show 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?

Beginner
A The stack is cleared completely B The stack frame for that function is popped off C The stack grows indefinitely D The stack remains unchanged
Show 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?

Beginner
A When the stack is empty B When too many frames are pushed onto the stack C When the stack pointer is reset D When a function completes execution
Show 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?

Beginner
A It stores the function's parameters B It tracks memory allocation C It saves local variables D It indicates where to return after the function finishes
Show 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?

Beginner
A For storing short-lived function call data B For managing global state C For dynamic memory allocation D For long-term data storage
Show 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?

Beginner
A Each recursive call pushes a new frame onto the stack B It only uses the heap for memory C It replaces the stack with a queue D It does not use the stack
Show 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?

Beginner
A Not having a base case in recursive functions B Returning too early from functions C Allocating too much heap memory D Using too many global variables
Show 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?

Beginner
A The call stack of active function calls B The source code line numbers C The global variable states D The heap memory allocation
Show 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?

Intermediate
A A region of the stack containing function call information B A memory allocation for global variables C A type of loop D A data structure for storing arrays
Show 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?

Intermediate
A It speeds up arithmetic operations B It allows functions to be called in any order C It supports recursion and nested calls D It stores data permanently
Show 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?

Intermediate
A Jump to function, push parameters, push return address B Push parameters, jump to function, push return address C Push return address, jump to function, push parameters D Push parameters, push return address, jump to function
Show 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?

Intermediate
A To point to the top of the stack B To point to the program counter C To point to the bottom of the stack D To point to global variables
Show 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?

Intermediate
A When the stack becomes empty B When the stack exceeds its allocated size C When the stack pointer is null D When a function returns too quickly
Show 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?

Intermediate
A By using a single stack frame for all calls B By using global variables C By avoiding function calls D By storing multiple return addresses and local variables
Show 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?

Intermediate
A Parameters B Return address C Global variables D Local variables
Show 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?

Intermediate
A It clears the entire stack B It adds a new function call C It removes the top function's data and returns control D It duplicates the top frame
Show 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?

Intermediate
A The stack frame remains, potentially causing a stack overflow B The stack frame is automatically removed C The program continues normally D The stack pointer resets
Show 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.

Intermediate
A True B False
Show answer & explanation

False

The direction of stack growth depends on the architecture; it can grow upwards or downwards.

Make your own

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