Possible Duplicate:
is i=i++ truly a undefined behavior?
i just want too explain ++ and — to my students and show them some code about them in visual studio 2010
I just test this code on it
int main(){
int a=3;
int b=3;
a=a++;
cout<<a<<endl;
cout<<b++<<endl;
}
I expect that both of cout print 3 but the first cout print 4!!!!
I test it in g++ and both of couts print 3…
what’s wrong???
The behavior of
a=a++is undefined. If you’d like to incrementa, usea++instead.