GATE Computer ScienceModerateGATE CS (PYQ pattern)

int i = 2, j = 3, k, m; k = i += j, j -= i, i * j; m = (i, j); printf("%d %d %d %d", i, j, k, m); What is printed?

  1. A. 5 -2 -10 -2
  2. B. 5 -2 5 5
  3. C. 5 2 5 2
  4. D. 5 -2 5 -2

Correct answer: D. 5 -2 5 -2

Assignment binds tighter than the comma operator, so the second line is (k = (i += j)), (j -= i), (i * j): k = 5, then j = 3 - 5 = -2, and i * j is computed and thrown away. In m = (i, j) the parentheses make the comma expression yield its right operand, -2.

More Programming and Data Structures (GATE) questions

Exams that ask this topic