GATE Computer ScienceVery hardGATE CSE · UGC NET

Procedure swap(x, y) { t = x; x = y; y = t; } is called as swap(i, a[i]) with i = 1 and a[1], a[2], a[3] = 2, 5, 9. Under call-by-name, what are the values of i, a[1], a[2], a[3] afterwards?

  1. A. i=1, a=[2,5,9]
  2. B. i=2, a=[2,1,9]
  3. C. i=2, a=[1,5,9]
  4. D. i=2, a=[2,5,2]

Correct answer: B. i=2, a=[2,1,9]

t = i = 1; x = y sets i = a[i] = a[1] = 2; y = t then assigns to a[i] with the NEW i = 2, so a[2] = 1: final i=2, a=[2, 1, 9].

More Compiler Design questions

Exams that ask this topic