0

about test questions

ā€¦ā€¦ int x=8; int y=7; x++; x+=y--; why the value of final x is16 not 9+6=15 Can anyone show me the calculating process,thanks.

5th Apr 2019, 3:57 PM
徐ęŒÆē¾½
1 Answer
+ 6
Because y will only be decremented after the assignment. x = y-- means: assign the value of y to x and decrement y afterwards. x = --y means: decrement y first and then assign the new value to x. So you would be correct if the code said x += --y.
5th Apr 2019, 4:14 PM
Anna
Anna - avatar