Lets Debug this step by step:
int i = 0;
→ i is initialized to 0. so i contains the value 0
++i
→ Pre-increment happens, so nows i becomes 1.
i + ++i
→ Substituting values:
i is 0
(original value before pre-increment).
++i makes i = 1
, so now ++i returns 1.
i + ++i = 0 + 1 = 1.
i = 1 (final value).
System.out.println(i); prints 1.
Your Next question Does the increment change the memory address?