GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 7.1

Aliased reference parameters with a shadowed local

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

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

Runtime Environments & Parameter Passing

Question 7.1, GATE 1993: Global m=0. P(var x,y:integer) has its own local m, sets that local m:=1, then x:=y+1. What is printed after P(m,m)?
Question 7.1, GATE 1993: Global m=0. P(var x,y:integer) has its own local m, sets that local m:=1, then x:=y+1. What is printed after P(m,m)?
Tap to enlarge
Select all that apply
Answer & solution

Answer: D: 1 because x and y both reference the global m (no official key was published)

Both formal reference parameters bind to the caller’s global m. The procedure’s separate local variable named m shadows the global name only for direct uses of that identifier in P; setting it to one does not change the caller’s m. Then x:=y+1 reads global m=0 through y and stores one through x. Consequently the global m printed by the caller is one. The result is not caused by the local m assignment, so the option giving that incorrect reason is not selected.

Original paper, page 6