What is an activation record?
a) A record of a function’s execution
b) A record of memory allocation in the heap
c) A record of global variables
d) A memory map of the code segment
Answer: a) A record of a function’s execution
Which part of the memory is responsible for storing activation records?
a) Heap
b) Stack
c) Static segment
d) Code segment
Answer: b) Stack
What does an activation record typically contain?
a) Local variables, return address, and function parameters
b) Only global variables
c) Dynamic memory allocation information
d) Code for the function
Answer: a) Local variables, return address, and function parameters
When is a new activation record created?
a) When a new function is defined
b) When a function is called
c) When a program starts execution
d) When a global variable is initialized
Answer: b) When a function is called
What happens to an activation record when the function returns?
a) It is stored in the heap
b) It is transferred to the global segment
c) It is popped off the control stack
d) It is transferred to the code segment
Answer: c) It is popped off the control stack
What is the purpose of the control stack?
a) To store dynamic memory allocations
b) To manage function calls and returns
c) To store global variables
d) To handle memory management for the heap
Answer: b) To manage function calls and returns
In which order are activation records pushed onto the control stack?
a) First In, First Out (FIFO)
b) Last In, First Out (LIFO)
c) Random order
d) Based on memory address
Answer: b) Last In, First Out (LIFO)
What is stored in the activation record’s return address field?
a) The memory address of the function call
b) The memory address where the program should continue after the function returns
c) The memory address of the local variables
d) The memory address of the heap allocation
Answer: b) The memory address where the program should continue after the function returns
Which of the following is NOT typically included in an activation record?
a) Return address
b) Function parameters
c) Global variables
d) Local variables
Answer: c) Global variables
What happens if a recursive function calls itself indefinitely without a base case?
a) Stack underflow
b) Stack overflow
c) Heap overflow
d) Infinite loop in the heap
Answer: b) Stack overflow
Which of the following actions results in a new activation record being pushed onto the control stack?
a) Declaring a global variable
b) Exiting a function
c) Calling a function
d) Allocating memory in the heap
Answer: c) Calling a function
What is the primary function of the control stack in function execution?
a) To manage dynamic memory allocations
b) To track the order of function calls
c) To store all program data
d) To manage file input/output
Answer: b) To track the order of function calls
How is a function call returned using the control stack?
a) By allocating memory in the heap
b) By copying the stack to the heap
c) By popping the function’s activation record off the control stack
d) By modifying the program counter
Answer: c) By popping the function’s activation record off the control stack
What happens to local variables in an activation record when the function ends?
a) They are transferred to the heap
b) They are copied to global memory
c) They are destroyed along with the activation record
d) They persist in the static segment
Answer: c) They are destroyed along with the activation record
Which of the following can cause a control stack overflow?
a) Allocating too much memory in the heap
b) Using excessive global variables
c) Deep or infinite recursion
d) Declaring too many static variables
Answer: c) Deep or infinite recursion
Which part of the activation record stores the function’s local variables?
a) Stack pointer
b) Return address
c) Local variable section
d) Code segment
Answer: c) Local variable section
What does the stack pointer do in relation to the control stack?
a) Points to the next free memory location in the heap
b) Points to the top of the control stack
c) Points to the global memory space
d) Points to the beginning of the data segment
Answer: b) Points to the top of the control stack
Which of the following can lead to a “stack underflow”?
a) Exceeding memory in the heap
b) Popping more activation records than exist on the stack
c) Allocating too many global variables
d) Calling functions with excessive parameters
Answer: b) Popping more activation records than exist on the stack
Which of the following control structures does NOT use activation records?
a) While loop
b) Recursive function
c) Nested function calls
d) Function with parameters
Answer: a) While loop
In a non-recursive program, what determines the number of activation records on the control stack?
a) The number of global variables
b) The number of loops in the program
c) The depth of nested function calls
d) The number of static variables
Answer: c) The depth of nested function calls
What information is required in the activation record to resume the function after it returns?
a) Local variable values
b) Return address
c) Function parameters
d) Stack pointer
Answer: b) Return address
How is the control stack utilized in exception handling?
a) By pushing exceptions onto the heap
b) By popping activation records until the exception is caught
c) By allocating new memory in the data segment
d) By copying exceptions to the code segment
Answer: b) By popping activation records until the exception is caught
What does the frame pointer do in an activation record?
a) Points to the beginning of the stack
b) Points to the start of the current activation record
c) Points to the global variables
d) Points to the next function call
Answer: b) Points to the start of the current activation record
What is the consequence of pushing too many activation records onto the control stack?
a) Memory leak
b) Heap overflow
c) Stack overflow
d) Segmentation fault
Answer: c) Stack overflow
In the context of the control stack, what is a “frame”?
a) A function’s return address
b) A block of memory used to store global variables
c) The memory space allocated for a function call
d) The space allocated for static variables
Answer: c) The memory space allocated for a function call
What is the primary difference between stack memory and heap memory?
a) Stack is used for global variables, heap is for function calls
b) Stack is automatically managed, heap requires manual management
c) Stack is larger than heap
d) Stack memory is slower than heap memory
Answer: b) Stack is automatically managed, heap requires manual management
What happens if the return address in an activation record is corrupted?
a) The function will return correctly
b) The function will not return, causing undefined behavior
c) The function will enter an infinite loop
d) The program will enter the heap for memory recovery
Answer: b) The function will not return, causing undefined behavior
Which of the following actions requires popping an activation record off the control stack?
a) Function call
b) Function return
c) Memory allocation in the heap
d) Static variable initialization
Answer: b) Function return
What happens to the control stack when a recursive function reaches its base case?
a) It begins to unwind the stack
b) It pushes more activation records
c) It transfers control to the heap
d) It modifies the global variables
Answer: a) It begins to unwind the stack
What can cause a segmentation fault in relation to the control stack?
a) Accessing memory outside the stack’s boundaries
b) Pushing an activation record for a global variable
c) Copying activation records to the heap
d) Popping too few activation records
Answer: a) Accessing memory outside the stack’s boundaries
How is memory for function parameters handled in an activation record?
a) Allocated on the heap
b) Stored in the static segment
c) Stored in the activation record on the stack
d) Managed by the operating system
Answer: c) Stored in the activation record on the stack
When are local variables removed from memory?
a) After the program terminates
b) After the function returns
c) When memory is freed from the heap
d) After the global variables are destroyed
Answer: b) After the function returns
Which of the following best describes stack unwinding?
a) Releasing global variables
b) Freeing memory in the heap
c) Reversing the function call sequence during a return
d) Initializing static variables
Answer: c) Reversing the function call sequence during a return
Which of the following situations can lead to undefined behavior during function calls?
a) Reusing activation records
b) Returning from a function without popping the activation record
c) Creating too many global variables
d) Declaring too many static variables
Answer: b) Returning from a function without popping the activation record
Which part of the memory stores function return values?
a) Stack
b) Heap
c) Global memory
d) Static memory
Answer: a) Stack
How are nested function calls handled in the control stack?
a) By reusing the same activation record
b) By pushing new activation records onto the stack for each call
c) By transferring control to the heap
d) By modifying global memory
Answer: b) By pushing new activation records onto the stack for each call
What happens when a function with parameters is called?
a) The parameters are passed via global memory
b) The parameters are copied into the function’s activation record on the stack
c) The parameters are stored in the heap
d) The parameters are copied to the static memory segment
Answer: b) The parameters are copied into the function’s activation record on the stack
What is the primary use of a “base pointer” in an activation record?
a) To track global variables
b) To reference local variables in the function
c) To manage memory in the heap
d) To store function return values
Answer: b) To reference local variables in the function
What causes the stack pointer to move during program execution?
a) Dynamic memory allocation
b) Function calls and returns
c) Global variable creation
d) Static variable initialization
Answer: b) Function calls and returns
What is the control stack’s relationship with recursion?
a) It pushes a single activation record for all recursive calls
b) It pushes a new activation record for each recursive call
c) It stores the entire recursion tree in the heap
d) It stops recursion at a predefined limit
Answer: b) It pushes a new activation record for each recursive call
In which segment are static variables stored?
a) Stack
b) Heap
c) Data segment
d) Text segment
Answer: c) Data segment
What does the control stack use to track active function calls?
a) Static segment
b) Dynamic segment
c) Activation records
d) Global memory
Answer: c) Activation records
Which of the following operations will NOT affect the control stack?
a) A recursive function call
b) Memory allocation in the heap
c) A nested function call
d) A function return
Answer: b) Memory allocation in the heap
What is the primary cause of stack overflow in recursive programs?
a) Too many static variables
b) Infinite recursion or deep recursion without a base case
c) Allocating too many local variables in a single function
d) Using global variables excessively
Answer: b) Infinite recursion or deep recursion without a base case
What is the relationship between the stack pointer and the activation record?
a) The stack pointer points to the base of the activation record
b) The stack pointer points to the global variables in the activation record
c) The stack pointer points to the top of the activation record
d) The stack pointer manages heap memory within the activation record
Answer: c) The stack pointer points to the top of the activation record
What is the consequence of calling a function that modifies the stack pointer incorrectly?
a) The function will complete successfully
b) The program may crash or exhibit undefined behavior
c) The program will enter an infinite loop
d) The function will skip its return statement
Answer: b) The program may crash or exhibit undefined behavior
What happens if you try to return from a function without a valid activation record?
a) The function returns normally
b) Undefined behavior occurs, likely causing a crash
c) The function skips the return value
d) The function uses static memory for the return
Answer: b) Undefined behavior occurs, likely causing a crash
In what order are activation records popped from the control stack?
a) First In, First Out (FIFO)
b) Last In, First Out (LIFO)
c) Based on memory address
d) Random order
Answer: b) Last In, First Out (LIFO)
How does a “frame pointer” help in debugging?
a) By pointing to the current function’s global variables
b) By maintaining a stable reference to the activation record even if the stack pointer moves
c) By managing heap memory allocations
d) By ensuring that recursive calls terminate
Answer: b) By maintaining a stable reference to the activation record even if the stack pointer moves
Which of the following would not cause a stack overflow?
a) Infinite recursion
b) Deep recursion without a base case
c) Allocating too many local variables
d) Memory allocation in the heap
Answer: d) Memory allocation in the heap