This is probably incorrect. See http://en.wikipedia.org/wiki/Unspecified_behavior#Order_of_evaluation_of_subexpressions I think in C/C++ there is no guarantee that the left part (i++) is going to be evaluated before the right part (i--). This behavior can be different between compilers. This has nothing to do with operator precedence.
Such ordering in Java is more strictly defined, but not in C/C++. See also: http://forums.topcoder.com/?module=Thread&threadID=673205 (similar case in C/C++). -Kurniady On Tue, Jun 8, 2010 at 6:53 PM, Vinay Julme <[email protected]> wrote: > i = 3; > i = i++ + i--; > out put would be 7. > game of operator precedence. > > > On Tue, Jun 8, 2010 at 12:30 PM, Manish kumar Singh <[email protected]> > wrote: >> >> Can any one explain what will be the value of 'i' after the statement >> i = 3; >> i = i++ + i--; >> >> both in C++ and Java. >> >> On 6/8/10, cornerstone <[email protected]> wrote: >> > "So, the effect of the "++" is applied >> >> BEFORE the effect of the assignment" >> > dude it is not lyk dat post increment operator increments the d value >> > after the statement is executed and the complete statement ends after >> > dat semicolon here n here d statement is n=n++; >> > so the thing is dat the value of n is not incremented bfore d >> > execution of the whole statement is over.(as yew hav done in ur >> > explanation) >> > n=10;//ok >> > n=n++;//n holds now a value of 10 during the execution of this >> > statement and 11 after the execution of this statement >> > >> > -- >> > You received this message because you are subscribed to the Google >> > Groups >> > "google-codejam" 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/google-code?hl=en. >> > >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "google-codejam" 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/google-code?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "google-codejam" 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/google-code?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-codejam" 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/google-code?hl=en.
