Question discussion

What is the output of the following C program?#include int main() { int x = (printf("A"), printf("BC"), 7); printf("%d", x); return 0; }

1779Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int x = (printf("A"), printf("BC"), 7);
    printf("%d", x);
    return 0;
}
  • A7
  • BA7
  • CABC7
  • DBC7
Correct answer: C

Explanation

The comma operator evaluates its operands from left to right, printing A and then BC, and yields the last value 7, which is then printed.

Discussion 0

Nobody has replied yet. Start the discussion!