In Java
int a=10; a = a + ++a; System.out.println(a); it prints 21. I had understood that it would print 22
I had understood that since '++' has higher precedence, so it will be calculated first and it will change a's value as it is pre-increment, so increment to variable 'a' would happen there and then...later it should add with a's latest value
like below:
a = a + 11; // (a is 11 after pre - increment) so, now a = 11 + 11 = 22, but program produces o/p = 21.
means it is not picking a's latest value which is 11, and using the old value which was 10
a = 10+ 11 = 21 .. can someone please clear my doubt?
would appreciate it if the answer contains the concept/reference from any book or java specification