+ 5

Question in Java

Why the statement : x=x++ does not change the value of x?

15th Apr 2017, 3:47 AM
Nizar GANNOUNI
Nizar GANNOUNI - avatar
6 Answers
+ 16
😵One day I shall master this concept. One day... 🤕
5th May 2017, 2:31 PM
ɔ͒̋ᴉ̼̻̤͙͇͈̓ͧʇ̋̌̃ḓ̣ͯʎ̱̝̗̗̺̐͊ɹʞ͇̮́̍̾̽̈́̓
ɔ͒̋ᴉ̼̻̤͙͇͈̓ͧʇ̋̌̃ḓ̣ͯʎ̱̝̗̗̺̐͊ɹʞ͇̮́̍̾̽̈́̓ - avatar
+ 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.
15th Apr 2017, 3:54 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 9
Post incremental function. x=x++ ~ x=x
15th Apr 2017, 3:49 AM
Pixie
Pixie - avatar
+ 5
in post increment value of x is assigned first after that increment will be done
15th Apr 2017, 10:55 AM
Player
Player - avatar
+ 1
but we speak about the same variable!!!!
15th Apr 2017, 10:57 AM
Nizar GANNOUNI
Nizar GANNOUNI - avatar
0
x++ is a post incremental function and it will change the value of x after one execution
15th Apr 2017, 2:50 PM
Ajinkya Bodke
Ajinkya Bodke - avatar