How this program runs?? I don't know how 3 3 1 prints out..Please can u explain this code?.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How this program runs?? I don't know how 3 3 1 prints out..Please can u explain this code?..

Here is the code #include <stdio.h> int main() { int a=1; printf ("%d %d %d",a,++a,a++); //Output is 3 3 1 //How???? return 0; }

8th Apr 2019, 4:53 AM
Zothansanga Renthlei
Zothansanga Renthlei - avatar
2 Answers
+ 2
Don't try to analyze them. Multiple postfix/prefix increment operators used between two sequence points, cause undefined behavior. The results are compiler dependent. https://stackoverflow.com/questions/949433/why-are-these-constructs-using-pre-and-post-increment-undefined-behavior
8th Apr 2019, 5:05 AM
Fermi
Fermi - avatar
+ 1
thanks...
8th Apr 2019, 5:10 AM
Zothansanga Renthlei
Zothansanga Renthlei - avatar