increment/decrement operators

hi,

In the following program.

void main()
{
int a=1;
cout<<a++<<"\t"<<++a<<"\t"<<a++<<endl;
}

if i execute the above program i should get 1 3 3.
but i'm getting different values when I executed this program.
The values that I get after execution are 3 3 1.

I am confused...please help
Last edited on
if i execute the above program i should get ...
In fact its impossible to say what the output should be. Modifying a variable more than once in the same statement gives undefined results. There is no correct result. The only recommendation is: don't write code which causes undefined behaviour like this.
The behavior of the program in Undefined.
For example see this output , http://coliru.stacked-crooked.com/a/4f3702f9bd502820 ( also the warning)
3 4 1


See http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points .
Topic archived. No new replies allowed.