What is an activation record in the context of program execution?
An activation record is a block of memory that stores information about a single execution of a procedure or function. It typically contains the function's parameters, local variables, return address, and control information.
Click to reveal answer
beginner
What role does the call stack play during program execution?
The call stack keeps track of active function calls in a program. Each time a function is called, an activation record is pushed onto the stack. When the function finishes, its activation record is popped off, returning control to the caller.
Click to reveal answer
intermediate
Why is the call stack important for nested or recursive function calls?
The call stack allows the program to remember where to return after each function call, even when functions call other functions or themselves recursively. It keeps each call's data separate and organized.
Click to reveal answer
intermediate
What information is typically stored in an activation record?
An activation record usually stores: function parameters, local variables, return address (where to continue after the function ends), and sometimes saved registers or control links.
Click to reveal answer
advanced
How does the call stack help in error handling like stack overflow?
If too many functions are called without returning (like in infinite recursion), the call stack grows beyond its limit, causing a stack overflow error. This helps detect problems in program flow.
Click to reveal answer
What happens to the activation record when a function finishes execution?
AIt remains on the call stack permanently
BIt is pushed onto the call stack
CIt is copied to another stack
DIt is popped off the call stack
✗ Incorrect
When a function finishes, its activation record is removed (popped) from the call stack to return control to the caller.
Which of the following is NOT typically stored in an activation record?
AUser interface settings
BLocal variables
CReturn address
DFunction parameters
✗ Incorrect
User interface settings are unrelated to function execution and are not stored in activation records.
Why is the call stack called a 'stack'?
ABecause it stores data in a queue order
BBecause it stores data in a last-in, first-out order
CBecause it stores data randomly
DBecause it stores data permanently
✗ Incorrect
The call stack uses last-in, first-out (LIFO) order, meaning the most recent function call is handled first.
What problem can occur if the call stack grows too large?
AStack overflow
BSyntax error
CMemory leak
DInfinite loop
✗ Incorrect
If the call stack exceeds its size limit, a stack overflow error occurs, often due to deep or infinite recursion.
Which of these best describes the purpose of the return address in an activation record?
ATo store the function's local variables
BTo save the function's parameters
CTo know where to continue after the function ends
DTo keep track of the program's memory usage
✗ Incorrect
The return address tells the program where to resume execution after the current function finishes.
Explain what an activation record is and what information it contains.
Think about what a function needs to remember while it runs.
You got /5 concepts.
Describe how the call stack manages multiple function calls, including recursive calls.
Imagine stacking plates and removing them in reverse order.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of an activation record in a program's execution?
easy
A. To store information about a function call such as parameters and local variables
B. To manage the computer's memory allocation for the entire program
C. To compile the source code into machine code
D. To display output on the screen
Solution
Step 1: Understand what an activation record stores
An activation record holds details about a specific function call, including parameters, local variables, and return address.
Step 2: Identify the main purpose
This helps the program keep track of function calls and return correctly after execution.
Final Answer:
To store information about a function call such as parameters and local variables -> Option A
Quick Check:
Activation record = function call info [OK]
Hint: Activation record = function call details stored [OK]
Common Mistakes:
Confusing activation record with overall memory management
Thinking activation record compiles code
Assuming activation record handles output display
2. Which of the following correctly describes the call stack's behavior during function calls?
easy
A. It executes functions in parallel without stacking
B. It removes the activation record before the function starts
C. It stores all activation records in a queue structure
D. It adds a new activation record on top when a function is called
Solution
Step 1: Recall how the call stack works
The call stack adds (pushes) a new activation record on top each time a function is called.
Step 2: Confirm the correct description
This stacking ensures the program knows which function is currently running and where to return after completion.
Final Answer:
It adds a new activation record on top when a function is called -> Option D
Quick Check:
Call stack pushes activation records [OK]
Hint: Call stack pushes new records on function call [OK]
Common Mistakes:
Thinking activation records are removed before function starts
Confusing stack with queue behavior
Assuming functions run in parallel without stacking
3. Consider this sequence of function calls: main() calls funcA(), which calls funcB(). What is the order of activation records on the call stack just before funcB() finishes?
medium
A. funcB at bottom, funcA in middle, main on top
B. funcA at bottom, main in middle, funcB on top
C. main at bottom, funcA in middle, funcB on top
D. funcB at bottom, main in middle, funcA on top
Solution
Step 1: Understand call stack order
The call stack adds activation records in order of calls: main first, then funcA, then funcB on top.
Step 2: Determine stack order before funcB finishes
Since funcB is currently running, its record is on top, with funcA below it, and main at the bottom.
Final Answer:
main at bottom, funcA in middle, funcB on top -> Option C
Quick Check:
Call stack order = main, funcA, funcB [OK]
Hint: Last called function's record is on top [OK]
Common Mistakes:
Reversing the order of activation records
Confusing bottom and top of the stack
Assuming parallel execution changes stack order
4. A programmer notices that after a function returns, the call stack still contains its activation record. What is the most likely cause?
medium
A. The function was never called
B. The activation record was not properly removed (popped) from the stack
C. The call stack is implemented as a queue
D. The program has no functions
Solution
Step 1: Understand normal call stack behavior on return
When a function finishes, its activation record should be removed (popped) from the call stack.
Step 2: Identify cause of leftover activation record
If the record remains, it means the stack pop operation did not happen correctly.
Final Answer:
The activation record was not properly removed (popped) from the stack -> Option B
Quick Check:
Activation record must be popped after return [OK]
Hint: Function return must pop activation record [OK]
Common Mistakes:
Assuming function was never called
Confusing stack with queue behavior
Ignoring that program has functions
5. In a recursive function that calls itself 4 times before returning, how many activation records will be on the call stack at the deepest point of recursion?
hard
A. 5
B. 2
C. 1
D. 4
Solution
Step 1: Understand recursion and activation records
Each recursive call adds a new activation record to the call stack.
Step 2: Count total activation records
If the function calls itself 4 times, there are 4 new calls plus the original call, totaling 5 activation records on the stack.
Final Answer:
5 -> Option A
Quick Check:
Recursive calls + original = 5 activation records [OK]
Hint: Count original call plus recursive calls [OK]
Common Mistakes:
Counting only recursive calls, ignoring original
Assuming recursion does not add activation records
Confusing number of calls with return points
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.