+ 2
Not understand the output (solved)
7 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.
+ 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.
0
Martin Taylor
Please write in steps how this code works