GATE Computer ScienceHardGATE CS (PYQ pattern)

int a = 0, b = 0, c = 0; int r = (a++ && b++) || (++c && a++) || (b++ || ++c); printf("%d %d %d %d", r, a, b, c); What is printed?

  1. A. 1 2 1 1
  2. B. 1 1 0 1
  3. C. 1 2 0 1
  4. D. 1 2 0 2

Correct answer: C. 1 2 0 1

a++ yields 0 (a becomes 1), so b++ is skipped. ++c gives 1, then a++ yields 1 (a becomes 2), so the whole || chain stops before the last group. r = 1, a = 2, b = 0, c = 1.

More Programming and Data Structures (GATE) questions

Exams that ask this topic