int a = 10; System.out.println(a-- * a--);what will be the output of these print statement and why??
in post decrement we actually observe that
- the value is used before getting change
but here I am getting in one of the operator (a--) is 10 and in another operator (a--) with which we are multiplying is getting 9.
overall the output which I came across is 100 but the actual output is 90
please explain how?
Java sees
A * B, so it first needs to compute both arguments, A and B.The left operand (A)
a--is executed, makinga = 9, but returning the value it had before, so10.We now have
10 * a--. Next, Java executes the right operand (B) and we geta = 8, but we use the value it had before the decrement, so9.We get
10 * 9, which is90. Anda = 8.