0
Increments help please!
help! why does this spit out "2 1" and not "1 2" ? #include <iostream> using namespace std; int main() { int x=1; cout <<x++ << " " <<x++; return 0; }
2 Respuestas
0
There's no sequence point with the << operator
This will give u the expected answer.
#include <iostream>
using namespace std;
int main() {
int x=1;
cout <<x++;
cout<<" ";
cout << x++;
return 0;
}
try below links.
http://stackoverflow.com/questions/2129230/cout-order-of-call-to-functions-it-prints
http://stackoverflow.com/questions/10778627/why-is-i-i-1-undefined-behavior-in-c11
0
In my opinion...it is called Cascading of Operators. When we use two or more shift operators (<<), then the processing starts from the end of the statement. Thus, in your question case, since the processing starts from left... the value of right one is 1 and the left one is 2. Since it is displayed from left to right (as usual)... hence the answer is: 2 1.
Hope this helped you.:)