GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 2.17

Aliasing under call by reference

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

GATE 2001, Q2.17 2 marks · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 2.17, GATE 2001: Caller variables begin x=10,y=3 and call func1(y,x,x) by reference, then print x,y. The callee’s formals are x,y,z and execute y=y+4; z=x+y+z. Choose 10,3; 31,3; 27,7; or none.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

Step 1: Rename the caller variables X=10,Y=3 to avoid confusing them with formal names. The call func1(Y,X,X) makes formal x alias Y, while both y and z alias the same caller variable X.

Step 2: y=y+4 changes X from 10 to 14. Then z=x+y+z reads 3+14+14=31 and stores 31 in X. Y is never assigned and remains 3.

The caller prints 31 and 3, B. Treating y and z as separate copies would miss the aliasing effect; this is reference-passing pseudocode, not ordinary C scalar call-by-value.

Original paper, page 6