Why does the code result in 7? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
12th Apr 2020, 8:50 AM
Zechariah YAKAP
Zechariah YAKAP - avatar
2 Answers
+ 2
Zacq x = 0 y = 5 z = x++ + ( ++x + y--) Here, x++ makes use the 0 value of x then increases so now, z = 0 + (++x + y--) But, x = 1. Then we have ++x, which makes our x=2 then uses its value. z = 0 + (2 + y--) Then we have y--, which uses y's value then decreases. So, z = 0 + ( 2 + 5) z = 7 At the end, x = 2, y=4, z=7
12th Apr 2020, 10:21 AM
Mustafa K.
Mustafa K. - avatar
+ 4
Mustafa K. Thanks! makes sense, so increment(decrement) applies from left to right and carries the changes forward. My mistake was to take the same line as just one block
12th Apr 2020, 10:27 AM
Zechariah YAKAP
Zechariah YAKAP - avatar