int x = 7;
x = x++;
What happens when there's a code like this? Does the variable increase after calculation and assign a value to itself? When I compiled it, x still has a value of 7. In my book, it says that the value of x increases... What is it?
java post-increment operator
The x itself is incremented. However, x assigns itself the previous x value.
x=x++;
In the syntax, x++ returns the value of x before x increases, but returns before x increases. So at x=, the value of x before x is increased, 7 is substituted.
In conclusion, x is increased, but x is substituted with the initial x value, so the value is 7.
© 2024 OneMinuteCode. All rights reserved.