Not understand the output (solved) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Not understand the output (solved)

Why 9?? https://code.sololearn.com/cznKO00eOVdQ/?ref=app

9th Jan 2021, 11:52 PM
Evgeniy Belov
Evgeniy Belov - avatar
3 Answers
+ 1
Martin Taylor well, thanks for noting that, i tested my assumption in several variations of the code and it seemed to follow a pattern despite the code being invalid. Didn't knew that such a mistake can make the output unpredictable in some cases UPD: Searched some more info on that, and turns out that unlike java, C does not guarantee the order of evaluation of individual operation in an expression. Now i definitely get it.
10th Jan 2021, 2:12 AM
Qwerty Uiop
Qwerty Uiop - avatar
+ 1
Increment operator execute from right to left. So, initially a=2; Now, in next line a++ + a++ = 3+2. After execution of this instruction , complier move to left side, and now value of 'a' become 4. So, again a++ + a++ = 5+4. Hence, 9 is assigned in k. And compiler so the output 9.
10th Jan 2021, 4:28 AM
Ashish Gupta
Ashish Gupta - avatar
0
Martin Taylor Please write in steps how this code works
10th Jan 2021, 7:47 AM
Evgeniy Belov
Evgeniy Belov - avatar