GATE Computer ScienceModerateGATE CS (PYQ pattern)

Nested procedures: main (depth 1) contains A (depth 2); A contains B (depth 3); B contains C (depth 4). C also calls itself recursively three times from the first call. Within the innermost recursive activation of C, how many access links must be followed to reach (i) a variable declared in A, and (ii) one declared in main?

  1. A. 5 and 6
  2. B. 2 and 3
  3. C. 3 and 4
  4. D. 2 and 2

Correct answer: B. 2 and 3

Access links follow lexical nesting, not the call chain: every C frame's link points to a B frame, so A is 4 − 2 = 2 links away and main is 4 − 1 = 3 links away, however deep the recursion is.

More Compiler Design questions

Exams that ask this topic