In printf, the cursor goes to left to right. so x++ + ++x + x++ 5 + 7 +7 = 19. ( Here x=5, then we put 5 in place of first x, after that x will be incremented(post increment) that means x is 6 and we take second x which is pre-increment and hence once again x will be incremented that means x is 7 and we put 7 in place of second x after we take third x which is also 7. after it will be incremented but here we will not take the incremented value.) 19 is correct answer.
On 28 August 2010 17:17, Raj N <rajn...@gmail.com> wrote: > The output is undefined. Depends on the compiler. + is not a sequence point > which may result in undefined behavior > > > On Sat, Aug 28, 2010 at 5:05 PM, jagadish <jagadish1...@gmail.com> wrote: > >> I ran this code.. >> >> int main() { int x=5; >> printf("%d",(x++ + ++x + x++)); >> } >> >> The output printed was 18 instead of 19.. Should it not be 19? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> 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 algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.