0

Help! How this results 5

x=1; x++ + x++ * --x=5 How???

18th Sep 2019, 11:56 AM
Suraj keshwani
Suraj keshwani - avatar
4 odpowiedzi
+ 1
1+2*2 The first x is 1, the second x is 2, the third x is 3-1, i.e. 2
18th Sep 2019, 12:17 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 4
The first x uses the value 1, but adds 1 for the next value. The second x thus equals 2 and adds 1 for the third x. The third x is 3-1, i.e. 2
18th Sep 2019, 4:23 PM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 1
Why is the first x 1 and second x 2? Mikhail Gorchanyuk AFAIK x++ first uses the x value and than increments --x decrement first and then increments so shouldn't it be 1st x 1, 2nd x 1 and third x 0?
18th Sep 2019, 3:40 PM
HNNX 🐿
HNNX 🐿 - avatar
+ 1
So each time x "appears" in code it gets incremented by 1? I thought each end of statement (;) increments it
18th Sep 2019, 9:46 PM
HNNX 🐿
HNNX 🐿 - avatar