+ 4
How this program works?
#include <stdio.h> int main() { int i=10; printf("%d %d %d %d %d",i++,++i,i,++i,i++); } Output 13 14 14 14 10
5 ответов
+ 1
Anyway, the algorithm is not casual.
In GCC for x86, this seems the behaviour:
evaluations and pushes (function arguments) are performed from right to left, starting from evaluations and passing to pushes as soon as a postincrement is found.
So we start evaluating at right:
(5) (4) (3) (2) (1)
i++ ++i i ++i i++
-- (1) is evaluated: postincrement, so before we push 10 at position 1
-- evaluating up to next postincrement: 12, 13
-- at postincrement position (5) is pushed 13 and evaluated 14
-- pushes are completed at positions (4),(3),(2) with last evaluated value 14
Other examples:
https://code.sololearn.com/cIA2q5PDVs7d/?ref=app
0
Its work as a last in first out last value out first so its. ++ Times it 13 ..... Then then last i++ value increment 14 and first i++ its 10