+ 2

What is output of these code and how?

#include <stdio.h> int main() { int i=2; printf("%d, %d\n", ++i, ++i); return 0; }

8th Sep 2017, 1:05 PM
Rishab Solanki
2 Antworten
+ 5
I checked this code and output is found to be 4,4. I think this is because comma operator works from left to right. So, the output is twice incremented in both cases.
8th Sep 2017, 1:20 PM
Lakshay
Lakshay - avatar
+ 1
if you run that #include <stdio.h> int main() { int i=2; printf("%d, %d, %d\n", ++i, ++i, i++); return 0; } result is 5,5,2 so the reason of these results is that before to show, compiler run operations ++i as theory said
8th Sep 2017, 1:39 PM
Daniel
Daniel - avatar