+ 1
Hello everybody i have a qustion?
why when i write this code #include <iostream> using namespace std; int main() { int x=5;int y=6; cout<<"\n"<<x++<<++y<<y++<<++x<<"\n\n"; return 0; } it prints:6867 and thank you.
1 Antwort
+ 9
lets write the cout and assign numbers to each ++ operation which happens
int x=5;int y=6;
(3) (1) (4) (2)
cout<<"\n"<< x++ << ++y << y++ << ++x <<"\n";
now, 1,2 happens before the printing of the values, meaning that x and y are incremented by 1 BEFORE being printed
3,4 happens after the values have been printed
and if you you will have another
cout << x << y;
you will see that the values have once again been incremented
[edit]
my bad, wrong answer xD
brb with an answer
look here:
http://www.c4learn.com/c-programming/increment-operator-inside-printf/
this is in c++ cout
http://stackoverflow.com/questions/33445796/increment-and-decrement-with-cout-in-c
seems this is an undefined behaviour and it is dependant on the compiler