0

I have this code:

int i = 0;
i = ++i; //pre increment
System.out.println(i); //Prints 1

But if I cahnge:

int i = 0;
i = i++; //post increment
System.out.println(i); //Prints 0

Why?

Joan P.
  • 1,891
  • 3
  • 20
  • 42
  • what ... makes you think it doesn't work? the point is, you assign a value to i, and then increment the value you 've dropped. You should learn how to use that operator, instead of assuming it doesn't work – Stultuske Jan 19 '22 at 08:15
  • 2
    isn't this already been asked on StackOverflow? [What is x after "x = x++"](https://stackoverflow.com/q/7911776/16320675) – user16320675 Jan 19 '22 at 08:16
  • @user16320675- [Yes](/search?q=%5Bjava%5D+postfix+increment+assignment). – T.J. Crowder Jan 19 '22 at 08:17

0 Answers0