In i = i-- - --i
you have:
i--
, a post-decrement, which retrieves the current value ofi
(1
) and then decrementsi
to0
-
--i
, a pre-decrement, which decrementsi
again and retrieves the updated value,-1
So you end up with i = 1 - -1
which is 2
.
Needless to say, this sort of thing shows up on (silly) Java tests and such, but should never appear in production code.
1
solved I can not figure out why am i getting the result 2 [duplicate]