ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int main(void) {
    int x = 0;
    int y = (x = 5, x + 1);
    printf("%d %d", x, y);
}
  1. A. 0 6
  2. B. 5 6
  3. C. 0 1
  4. D. 5 5

Correct answer: B. 5 6

The comma operator evaluates its left operand (x=5, setting x to 5, discarding that assignment's value) then evaluates and yields its right operand (x+1 = 6) as the whole expression's value; y = 6, x = 5.

More C Programming questions

Exams that ask this topic