Question discussion

What will be the output of the following code?

359029Medium DSSSB TGT Computer Science 0 replies 0 views
0
What will be the output of the following code?
#include<stdio.h>
int main() {
    int x=5,y;
    y=x++ + ++x;
    printf("%d",y);
    return 0;
}
  • A11
  • Bcompile time error
  • C12
  • D10
Correct answer: C

Explanation

y = x++ + ++x with x = 5: x++ gives 5 (x becomes 6), then ++x makes x 7 and gives 7, so y = 12. (This is the result with the usual compilers; the expression is technically unspecified.)

Discussion 0

Nobody has replied yet. Start the discussion!