What happens if you write something like a = a++ in Java?
Posted: | Categories: Java, Programming
I often happened to see discussions about this topic. Basically, here is the question. If you have such a code:
int a = 0;
a = a++;
System.out.println(a);
What does it print?
More than 50% of the programmers will answer 1, some of the remaining will say “I don’t know” and the others will say 0. Well “the others” are right!
Provided that such a code MUST NEVER BE WRITTEN, let’s try to understand, for academic purposes, why it prints 0.
Read more...