can anybody explain this why its happening
int i=0;
i=i++;
i=i++;
i=i++;
System.out.println(i);
it prints zero.
Let I=++, an increase, and A=i, an assignment. They are non-commutative: IA != AI.
Summary
IA = "first increase then assignment"
AI="first assignment then increase"
Counter-Example
$ javac Increment.java
$ java Increment
3
$ cat Increment.java
import java.util.*;
import java.io.*;
public class Increment {
public static void main(String[] args) {
int i=0;
i=++i;
i=++i;
i=++i;
System.out.println(i);
}
}
Related