🧱 Runtime Environments
Why it matters: Scoping and parameter-passing output questions are classics.
Subtopics
Each subtopic has its own page: idea, why, how, example, play, check. Mark each one understood when it clicks. 0 of 4 done.
1Activation records and the control stack
2Static vs dynamic scoping
3Parameter passing
4Storage organisation: static, stack, heap
Formulas
Recursion depth
stack space ≈ depth × activation record size
Access link chain
to reach a variable declared k levels out, follow k access links (static scoping)
Call by name
argument expression is re-evaluated in the caller's environment each time the formal is used
What GATE asks from this
Question types seen repeatedly in past papers. More stars means more frequent.
★★★
Output under static vs dynamic scoping
Trace nested procedures that print a global/shadowed variable; compare the two rules.
★★★
Parameter passing result
Values after calling swap-like procedures by value / reference / name / copy-restore.
★★★
Activation record contents / stack depth
Maximum stack depth or which fields exist.
Ratings are approximate, based on recurring patterns in past GATE CSE papers.
Previous year questions
2 real questions from the official GATE CSE papers (2021 to 2023), newest first, each with the official answer key and a worked solution. Questions are the property of the GATE organising institutes; this copy is for your personal study.
2 questions · 0 correct of 0 attempted · marks 0 / 3
Year:
GATE 2023 · Q36MCQ2 marks
Consider the program:
(A) main → f1, f2, f3; the f2 node has children f3, f2; the inner f2 has children f3, f1. (B) main → f1, f2, f3; f2 has children f3, f1. (C) a chain main → f1 → f2, with f2 having children f3, f1. (D) main → f1, f2, f3; f2 has three children f3, f2, f1.
int main() {
f1();
f2(2);
f3();
return(0);
}
int f1() {
return(1);
}
int f2(int X) {
f3();
if (X==1) return f1();
else return (X*f2(X-1));
}
int f3() {
return(5);
} Which one of the following represents the activation tree corresponding to the main function? (A) main → f1, f2, f3; the f2 node has children f3, f2; the inner f2 has children f3, f1. (B) main → f1, f2, f3; f2 has children f3, f1. (C) a chain main → f1 → f2, with f2 having children f3, f1. (D) main → f1, f2, f3; f2 has three children f3, f2, f1.
GATE 2021 Set 1 · Q4MCQ1 mark
Consider the following statements. S1: The sequence of procedure calls corresponds to a preorder traversal of the activation tree. S2: The sequence of procedure returns corresponds to a postorder traversal of the activation tree. Which one of the following options is correct?
Common traps
Dynamic scoping looks at the caller, static at the definition.
With call by name, an index changed inside the procedure changes which array element is meant.