+ 2
Int x=4; x+=(x++)+(++x)+x;System.out.println (x);
the answer will be 20 can any one explain this question
6 Respuestas
+ 17
First, you have 4.
Then in the second line you have this:
4 += 4 + 6 + 6
x++ means you put value of x first and then it is incremented, so you got 4. In the case of ++x the value of x is incremented once again, that's why you got 6.
+ 4
20
0
++x increments then assigns value, x++ assings value then increments.
0
21 is coming 😑
0
The answer here should be 22. Below is the reason which I can see
x+=(x++)+(++x)+x
which is same as x=(x + ((x++)+(++x)+x)
Now with order of prioritty (x++) will be executed first.
x++ will increment the value of x first and return the old value, which is 4
Next ++x will be executed
++x will increment the value first and return the new value, which 6
Now our problem is changes like below
x=6
x=x+4+6+x
Which is 22!
However when I execute x=x + ((x++)+(++x)+x then I am getting 21. I am yet to figure out the reson why removal of bracket changes the execution
0
Var x = 4
X *= 2
X -=3
X++
Println(x)