Solved

# why x = 3; y = x++ * x++ then x=3 and y =9 ?

Posted on 2001-08-04

Look at the following code :

int x = 3;

int y = x++ * x++;

I though the result is x = 5 and y = 12, because

x++ * x++ is evaluated as

push x value on stack ; now stack has ... 3

x = x + 1; // x= 4

push x value on stack again ; now stack has ... 3 4

x = x + 1; // x = 5

// mul two nubers on stack

y = 3 * 4 ; ---> 12

However, when I run the above code in VC++ and C++ Builder,

the result is x = 5 and y = 9. Because the VC++, C++ Builder

evaluates x++ * x++ as

y = x+ x;

x++;

x++;

Could someone points out why the result is not x = 5 and y = 12 ?