For such type of questions, the best method is to draw a parse tree according to precedence and evaluate the tree. This is how it is evaluated at compiler level. Many times parsing tree creation is implementation dependent.
On Fri, Apr 29, 2011 at 6:43 PM, Varun Nagpal <varun.nagp...@gmail.com>wrote: > I think these questions are stupid in the sense that no one would ever use > these constructs in their production code unless someone wants to write an > obscure obfuscated code in some competition. Many times similar expressions > are non-portable. > > Anyways, to understand this and related concepts, please see iso c or c++ > standard and try to understand operator precedence, operator associativity > and sequence points. > > On Fri, Apr 29, 2011 at 3:06 PM, Nikhil Gupta > <nikhilgupta2...@gmail.com>wrote: > >> 12 >> 5 >> >> because y=4+4+3+1 >> and x is incremented to 5 >> >> >> On Fri, Apr 29, 2011 at 2:01 PM, MANNU <manishkr2...@gmail.com> wrote: >> >>> *Can anyone please explain me the output of this program:* >>> >>> int x=1; >>> int y=x++ + ++x + ++x + x++; >>> cout<<y; >>> cout<<x; >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algogeeks@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. >>> >> >> >> >> -- >> Nikhil Gupta >> Senior Co-ordinator, Publicity >> CSI, NSIT Students' Branch >> NSIT, New Delhi, India >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@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. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > -- With Regards Ashish Modi 9423721478 -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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.