ProgrammingModerateTCS NQT · Infosys pattern

What is printed (the code compiles)?

What is printed (the code compiles)?
int x = (5, 10, 15);
int y;
y = 5, 10;
printf("%d %d", x, y);
  1. A. 5 10
  2. B. 15 5
  3. C. 15 10
  4. D. 5 5

Correct answer: B. 15 5

The comma operator evaluates left to right and yields its last operand, so x = 15. But = binds tighter than the comma, so y = 5, 10; is (y = 5), 10; and y is 5.

More C Programming questions

Exams that ask this topic