+ 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

18th Aug 2019, 5:31 PM
Geek
Geek - avatar
5 Respostas
+ 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
19th Aug 2019, 3:59 PM
Bilbo Baggins
Bilbo Baggins - avatar
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
8th Feb 2020, 4:04 AM
A S Raghuvanshi
A S Raghuvanshi - avatar