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 ?

Shankar Modi
  • 71
  • 1
  • 1
  • 4

1 Answers1

2

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.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347