GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 7.3

Scope and shadowing of a global name

Compiler Design · Runtime Environments & Parameter Passing · Full GATE CSE 1993 paper

GATE 1993, Q7.3 2 marks · MSQ
Report issue

Runtime Environments & Parameter Passing

Question 7.3, GATE 1993: Global m is declared in PARAM. P declares another local m; Q does not. Where is the global name m directly visible?
Question 7.3, GATE 1993: Global m is declared in PARAM. P declares another local m; Q does not. Where is the global name m directly visible?
Tap to enlarge
Select all that apply
Answer & solution

Answer: C: PARAM and Q (no official key was published)

Lexical lookup in P finds its local m before reaching the enclosing declaration, so unqualified m there denotes the local variable. In Q, which has no local m, lookup reaches the global declaration in PARAM. The same global name is visible in the main block itself. Hence PARAM and Q are the regions of direct visibility, C. The global object can still be accessed indirectly through P’s reference parameters; object accessibility is distinct from whether its identifier is shadowed.

Original paper, page 6