GATE Computer ScienceHardGATE CSE · UGC NET

Procedure P(x, y) { x = x + 1; y = x + y; } is called as P(a, a) with a = 3. What is a after the call under call-by-reference, and under call-by-value-result (copy-in both formals, copy-out in left-to-right order x then y)?

  1. A. 7 and 8
  2. B. 8 and 3
  3. C. 8 and 7
  4. D. 8 and 8

Correct answer: C. 8 and 7

Reference: x and y alias a, so a=4 then a=4+4=8. Value-result: x=3,y=3 → x=4, y=4+3=7; copy-out x then y leaves a = 7.

More Compiler Design questions

Exams that ask this topic