'"cout" chaining while performing increment and decrement produces unexpected result
The following program includes simply increment and decrement operations. As my prediction the program should print "0 1 1 1" but it is printing "1 0 2 0" instead,but why?
#include<iostream>
using namespace std;
int main(void)
{
int i=0;
cout<<i++<<" "<<i++<<" "<<--i<<" "<<i++;//this will print "1 0 2 0"
}
...but it works fine if I don't chain the output command like,
cout<<i++<<endl;
cout<<i++<<endl;
cout<<--i<<endl;
cout<<i++<<endl;
Even if they should work in the same way but they are producing different results. But why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
