recursion – StackOverFlow in Postfix Decrement in JAVA
First, with the unary decrement operator, the operation is occurring after, or before, the statement.
As opposed to after, or before, the expression.
So, in this situation, there will be a difference between num--
and --num
.
-
doubt(num--)
is decrementing after the call statement, and not after the parameter expression. -
double(--num)
, the opposite is happening, the decrement is happening before the parameter expression.
Essentially, from a compiler’s stand-point, for the doubt(--num)
statement, you have the following.
- Get
num
- Decrement
num
- Apply
num
asdoubt
parameter - Execute
doubt
with parameter value
Alternately, with doubt(num--)
you have the following.
- Get
num
- Apply
num
asdoubt
parameter - Decrement
num
(which has no effect, since the parameter value was already set) - Execute
doubt
with parameter value
Essentially, for the doubt(num--)
statement, after the compiler has num
, and is ready to call doubt
, it will then decrement num
.
As opposed to having num
, then decrementing, and then calling doubt
.
Read more here: Source link