0

I was looking at a simple code fragment.

int x = 10;
x = x++;
cout << x << endl;

mingw compiler says the result is 10, as expected.. basically the statement x = x++; first the increment is done -- so x becomes 11; the expression evaluates to the value of x before the increment (which is 10), which is then assigned to x. So x has the value of 10.

however, the visual studio compiler says the answer is 11, and I am wondering why that is the case. Is it doing some optimization?

thanks, murali

0 Answers0