Desk checking

Can anyone try a desk check and see what you come up with.I will be glad for an explanation.To me the result is 11 and 16. But execution gives 12, 18.

1
2
3
4
5
6
7
Consider the following C++ code
int m = 1, n=5;
m = n++;
m += n;
n += ++m ;
Desk-check the above code and find out what are the values for m and n after the execution.
I get 12 & 18.

1
2
3
4
int m = 1, n=5; //m=1, n=5
m = n++; //m=5, n=6
m += n; //m=11, n=6
n += ++m ; //m=12, n=18 
Topic archived. No new replies allowed.