1

I came across a strange behavior while using increments operators in cout. The code is supposed to print 10 11 12 13 but it prints in reverse. ie 12 11 10 13.

int y = 10;
cout << y++ << y++ << y++ << y;

I tried doing

cout << y++ << y-- << y++ << y; 

and this works fine and print 10 11 10 11

Taimoor Ali
  • 158
  • 1
  • 7
  • 1
    See [here](https://stackoverflow.com/questions/949433/why-are-these-constructs-using-pre-and-post-increment-undefined-behavior). Basically the evaluation order for multiple increment or decrement operators on the same line is undefined. – ChrisD Sep 11 '19 at 05:26
  • 1
    Another link: https://stackoverflow.com/questions/7718508/order-of-evaluation-of-arguments-using-stdcout – Support Ukraine Sep 11 '19 at 05:29

0 Answers0