GATE / CS ARCHIVE

GATE CSE 1998 / QUESTION 2.13

Two reference-parameter function calls

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

GATE 1998, Q2.13 2 marks · MCQ
Report issue

Runtime Environments & Parameter Passing

Question 2.13, GATE 1998: In Pascal-like code, f (var x) increments x and returns it. Starting x=5, result=f (x)*f (x). Options 5, 25, 36, 42.
Tap to enlarge
Your answer
Answer & solution

Answer: D: 42 under sequential call evaluation (no official key was published)

The var parameter aliases the caller’s x, so the first completed call changes 5 to 6 and returns 6. The second then changes 6 to 7 and returns 7. Multiplication gives 6·7=42. Choosing the opposite operand first merely swaps these two returned values, leaving the product unchanged. Thus D in the ordinary sequential procedural evaluation model. This is not pass-by-value, which would give 6·6=36. The explanation does not import C’s unsequenced-expression rules into the displayed Pascal-like language.

Original paper, page 5