The order of evaluation of sub-expressions is not defined since there is no sequence point in the sub-expression. So, the behavior is not defined, and one cannot rely on a specific compiler implementation - gcc, MSVC, or any other.
As a general rule of thumb, you should avoid this type of complex expressions where the same object is modified within the sub-expressions. Regards, Ashot Madatyan From: [email protected] [mailto:[email protected]] On Behalf Of holmes Sent: Wednesday, May 30, 2012 3:21 PM To: [email protected] Subject: [algogeeks] Re: problem with increment operator It's output will be compiler dependent. So on Turbo C, compiler will perform all pre-increment operation first then will start adding. like in your problem all "++a" operation will go first. then addition will happen. so 6+6+6=18. on gcc, first two variables will it take, performs pre-increment operation and then adding and then third variable will come.as it continues. As in this case in gcc it will be performed like, (++a + ++a) + (a++)=(6+6)+6=18 post-increment will be unaffected during entire expression. Feel free to ask if you didn't got what i explained. On Monday, May 28, 2012 11:02:03 AM UTC+5:30, ashish wrote: #include<stdio.h> int main() { int a=4; printf("%d\n",++a + ++a + a++); return 0; } according to me output should be 17, but it is coming out to be 18. plz explain it?? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/eBcLatQS34kJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
