GATE Computer ScienceModerateGATE CS (PYQ pattern)

Procedures are nested as follows: main contains P (nesting depth 2); P contains Q (depth 3) and S (depth 3); Q contains R (depth 4). main's own variables are at depth 1. At run time main calls P, P calls Q, Q calls R and R calls S. When S starts, how many access links are followed from R's frame to build S's access link, and how many links does S then follow to reach a variable declared in main?

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

Correct answer: B. 2 and 2

S is declared in P, so its access link must point to P's frame: R (depth 4) → Q (3) → P (2) is 2 hops. From S (depth 3) a variable in main (depth 1) is 3 − 1 = 2 links away.

More Compiler Design questions

Exams that ask this topic