+ 5
Question in Java
Why the statement : x=x++ does not change the value of x?
6 odpowiedzi
+ 16
😵One day I shall master this concept. One day... 🤕
+ 15
Increment has higher precedence. So, x++ is evaluated first. So,
Step 1 : x=1 say
Step 2 : x++ is evaluated. It changes x to 2 but returns 1 (post increment)
Step 3 : RHS value (1) is assigned to x.
Hence, the value of "x" doesn't change.
+ 9
Post incremental function. x=x++ ~ x=x
+ 5
in post increment value of x is assigned first after that increment will be done
+ 1
but we speak about the same variable!!!!
0
x++ is a post incremental function and it will change the value of x after one execution