+ 1
can’t seem to understand.
i find understanding x++ and ++x very confusing, anyway of explaining and memorising it?
1 Antwort
+ 3
As far as I know, ++x increments the value of x and then returns x.
x++ returns the value of x and then increments.
For example:
x = 3, y = 3
- System.out.println(++x) --> 4
- System.out.println(x) --> 4
- System.out.println(y++) --> 3
- System.out.println(y) --> 4
As you can see in the first case, It first increases the value and then returns. On the other hand, x++ returns first the value and then increments.