public static void main(String[] args) {
int i = 0;
i = i++;
System.out.println(i);
}
This java code is printing value 0. How internally java assign value 0 to i instead of 1 ?
public static void main(String[] args) {
int i = 0;
i = i++;
System.out.println(i);
}
This java code is printing value 0. How internally java assign value 0 to i instead of 1 ?
The value of i++
is the value of i
as it was, and it has a side effect of incrementing i
(which is then immediately overwritten by the assignment)
Try assigning to j
instead.