Actually --x
is a pre decrement operation which will always be same as x=x-1;
ie decrement x by 1 first and then assign decremented value of x to x.
so x value will definitely changes when we perform --x
.
but x-1
is just an operation we are doing on x and operation is subtract.
here we are assigning this result into some argument in the method which is receiving this call. but its not reassigned to x automatically.
so x-1
is never ever equals x=x-1;
and hence x remains same, only receiver gets subtracted value.
hence
solve(string, --open, closed, ++index);
in the above statement , pre decrement is performed on open
.
so it is same as open=open-1;
and hence open value changed.
but
solve(string, open-1, closed, ++index);
above statement is subtracting 1 from open
and passing subtratced value to method.
its same as receiveing_variable_in_method_definition = open-1
but open is not changing.