Possible Duplicate:
Unexpected order of evaluation (compiler bug?)
I couldn't predict the output for this program :
#include<iostream>
using namespace std;
int *p(int *a)
{
(*a)++;
return a;
}
int main()
{
int i=0;
cout<<i++<<" "<<(*p(&i))++<<" "<<i++<<" "<<i<<endl;
return 0;
}
When compiled in vs2008, it outputs 3 2 0 4
. Can anybody explain why it's not 0 2 3 4
?
Note: It works great if there is no function call to p
.
Thanks in advance!