0
int a=2;
int b=++a -a;
printf("%d\n",b);
printf("%d %d %d",b,b++,++b);
return 0;

In the above code, I expected the output as : 0 0 0 2 But the output given by the compiler was 2 1 2 I do not understand how it's possible. Please explain.

  • Incrementing a variable and using the variable on the same line isn't a good idea. The order of evaluation is unknown (whether i is incremented already or not when you use i itself), and will cause undefined behavior. (It's not a simple left to right evaluation concept) Check out link on: https://en.cppreference.com/w/cpp/language/eval_order – Asphodel May 28 '22 at 18:49

0 Answers0