GATE Computer ScienceVery hardGATE CS (PYQ pattern)

int i = 1; int A[0..2] = {5, 6, 7}; void f(x, y) { x = x + 1; y = 10; } The call f(i, A[i]) uses copy-in/copy-out (value-result), copying back x first, then y. What is A after the call if the copy-out addresses are computed at call time, and if they are recomputed at return time?

  1. A. {5, 10, 7} and {5, 10, 7}
  2. B. {5, 6, 10} and {5, 10, 7}
  3. C. {5, 10, 7} and {5, 6, 10}
  4. D. {5, 6, 7} and {5, 6, 10}

Correct answer: C. {5, 10, 7} and {5, 6, 10}

Copy-in: x = 1, y = A[1] = 6; the body makes x = 2, y = 10. Copy-out writes i = 2 first. If A[i]'s address was fixed at the call it is A[1]: A = {5, 10, 7}. If it is recomputed at return, i is already 2, so y goes to A[2]: A = {5, 6, 10}, and A[1] keeps 6.

More Compiler Design questions

Exams that ask this topic