Can some one explain the output of below code
int a=10;
a = a -= a+= a -= a += a;
output : 10
I am not able to get how it is giving 10?
a += a
means a = a + a
.
likewise, a -= a
means a = a - a
.
I am not sure which way is proper to start, but if I convert the given code from the right using above,
a += a > a = a + a;
a -= a += a > a = a - (a + a);
a+= a -= a += a > a = a + (a - (a + a ));
a -= a+= a -= a += a > a = a - (a + (a - (a + a)));
a = a -= a+= a -= a += a > a = a - a - a + a + a;
where -a -a + a + a
cancels each other, resulting a = a
, which is 10
.