GATE / CS ARCHIVE

GATE CSE 1994 / QUESTION 1.20

Call by name versus call by reference

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

GATE 1994, Q1.20 MCQ
Report issue

Runtime Environments & Parameter Passing

Question 1.20, GATE 1994: Which argument can expose different results between call-by-name and call-by-reference: constant, array address, whole array, or an array element?
Tap to enlarge
Your answer
Answer & solution

Answer: D (array element) (no official key was published)

For an actual argument a[i], call-by-reference fixes the target location at call time. Call-by-name reevaluates the argument expression each time the formal is used. For example start i=1 and call a procedure whose body sets i:=2 then assigns 9 to the formal. Reference modifies a[1], while name modifies a[2]. Thus an array element whose index can change demonstrates the difference.

Original paper, page 3