The following code prints a value of 9. Why? Here return(i++)
will return a value of 11 and due to --i
the value should be 10 itself, can anyone ex
The postfix increment ++
does not increase the value of its operand until after it has been evaluated. The value of i++
is i
.
The prefix decrement increases the value of its operand before it has been evaluated. The value of --i
is i - 1
.
Prefix increment/decrement change the value before the expression is evaluated. Postfix increment/decrement change the value after.
So, in your case, fun(10)
returns 10, and printing --i
prints i - 1
, which is 9.