hi friends... i am running a program in turbo c and i have a confusion in it..just check it and tell me how it works. #include<stdio.h> #include<conio.h> main() { int a=4,b; clrscr(); b=a++ + ++a + a++; printf("%d",b); getch(); } when i am running this program it is showing the result: 15 #include<stdio.h> #include<conio.h> main() { int a=4; clrscr(); printf("%d",a++ + ++a + a++); getch(); } and when i am running this program it is showing: 16 i am confused about these outputs. both programs has same meaning. but they are showing different output.. can anybody explain with complete solution and exact answer.. Thanks in advance
I'm not really sure. Try surrounding the sum of the pre and post increemments of variable a in the "printf" statement with parentheses.
This one should give your answer: http://en.wikipedia.org/wiki/Sequence_point You may also try surrounding the upper code with parentheses and try to see what answer comes out. Also running the same code with different compiler may yield different results. In short it is not recommended to use code like that, since the behaviour is undefined.