When using the postfix
increment operator, it is important to know that the result of the expression x++
is the value before the operation
x
.
This means that in some cases, the result might not be what you expect:
- When assigning
x++
to x
, it’s the same as assigning x
to itself, since the value is assigned before the
increment takes place
- When returning
x++
, the returning value is x
, not x+1
The same applies to the postfix and prefix decrement
operators.