+ 1
Can anyone explain this java statement and the value of x after evaluating::- where int x=4
x+=(x++)+(++x)+x
9 Réponses
+ 1
x = x + x++ + ++x +x
=4 + 4 + 5 + 4.
=17.
Is it correct?
+ 1
Ok I got it.
x = x + x++ + ++x +x
=4
+ 4(now x=5)
+ 6 (x=6)
+ 6
=20.
because
IN PREFIX ++x FIRST x IS INCREMENTED AND THAN EVALUATION TAKE PLACE.
IN POSTFIX x++ FIRST EVALUATION IS DONE AND THAN ITS VALUE IS INCREMENTED.
Hope this helps ☺️☺️.
+ 1
Thanks
+ 1
MEET MEHTA genius!
0
That's what I thought earlier. But in the book it is written 20 and when I executed in Java, it too came as 20
0
If you know how the bracket function here works, please explain
0
but when I executed in Java, the answer came as 20
0
The answer 20 is also given in the book
0
Code?? I didn't get that. well, this was given in our book and can be executed in BlueJ