+ 1

Why is the output of the following C code 10 41 ?

int main() { int e=5,f=0; f=(++e) + (++e) + (++e) + (++e) + (++e); printf("%d %d\n",e,f); return 0; } It should be 10 40 but it's coming out to be 10 41.

8th Sep 2019, 3:48 PM
Rishu Kumar
Rishu Kumar - avatar
1 Resposta
+ 1
Using ++ operator more times in single line is UNDEFINED. You never know what will come up, depends on compiler or compiler flags
8th Sep 2019, 4:08 PM
Elva
Elva - avatar