ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int a = 1, b = 2, c = 3;
a += b -= c *= 2;
int d = (a, b) > c ? a-- : c++;
printf("%d %d %d %d", a, b, c, d);
  1. A. -3 -4 6 7
  2. B. 3 -4 7 6
  3. C. -3 -4 7 6
  4. D. -4 -4 7 6

Correct answer: C. -3 -4 7 6

Assignment operators group right to left: c *= 2 makes c 6, b -= 6 makes b −4, a += −4 makes a −3. In (a, b) the comma operator discards a and yields b = −4; −4 > 6 is false, so the third operand c++ is evaluated: d gets the old value 6 and c becomes 7. a-- is never evaluated, so a stays −3.

More C Programming questions

Exams that ask this topic