Here is the portion of the code which works weird while debugging
public static void main(String[] args) { //Line-1
int a = 5; //Line-2
System.out.println(++a); //Line-3
} //Line-4
When I run it in normal mode it gives output as 6
which is correct. But while debugging I kept a break point at Line-3
and first time when I inspected the value of ++a
it showed 6 next time it was 7,8,9...
When I ended the program it showed output as 10 in the console. Why is that?
These solutions C++ - Eclipse behavior is different while debugging and running, How post Increment ++ Operator works while initialization didn't give any proper idea.