Also guys, this link: http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr
discusses erroneous expns like a[i]=i++; But if u run this code..this gives no error on GNU compiler.. So, are we really referring to a reliable document here..? http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr I really doubt that...! Run it on as many different systems as you can...! Lets c what all results we get...!! Pls give ur feedback... On 8/8/11, Puneet Gautam <[email protected]> wrote: > @ Amit: Well, the link you have posted refers that i++*i++ is not an > invalid expression, it just runs differently on different OS's because > every OS has a different implementation on how to solve such > expressions that use the same address space(Address of the integer i). > > As far as i know the value of a variable can be increased multiple > times on most OS's ... i have tried it on TUrbo running on WIN 95 as > well as Dev Cpp on WIN 7 OS. > > Though it may give different output on Unix OS's like Linux but:\ > > Hey, we can only predict the output as we see is apt as far as we > have learnt in books. > > And the output in my first post does the processing the bookish way... > > BUT THE CODE WILL NOT GIVE ANY ERROR ....!!! > > > > On 8/3/11, Arun <[email protected]> wrote: >> >> What Amit told is exactly correct. But I would like to know the >> expression evaluation order of this in gcc and turboc >> >> >> Arun >> On Aug 3, 6:15 pm, Arun Vishwanathan <[email protected]> wrote: >>> @amit:+1 >>> >>> On Wed, Aug 3, 2011 at 3:14 PM, amit karmakar >>> <[email protected]>wrote: >>> >>> >>> >>> >>> >>> >>> >>> > You are wrong. >>> > The above program invokes undefined behavior. Read the standard >>> > language draft to know about sequence points, side effects and >>> > undefined behavior. >>> >>> > Between a previous and next sequence point a variable's value cannot >>> > be modified twice. >>> > c-faq should be quite useful >>> >http://c-faq.com/~scs/cgi-bin/faqcat.cgi?sec=expr >>> > On Aug 3, 5:20 pm, Puneet Gautam <[email protected]> wrote: >>> > > As we know: >>> > > In an expression, if pre n post occur >>> > > simultaneously, pre inc the value then n there only n post executes >>> > > it >>> > > after that expression...and expression evaluates right to left... >>> >>> > > Also, the value of a variable in an expression can be modified >>> > > multifold times...there is no restriction on dat... >>> >>> > > Here in this code: >>> > > Print statement No.: >>> >>> > > 1. i++*i++ is equivalent to: >>> > > output i*i(7*7) >>> > > followed by >>> > > i=i+1; >>> > > i=i+1; >>> > > prior to 2nd printf statement..that makes i=9 >>> >>> > > 2. i++*++i >>> > > expn. evaluates right to left: i inc. by one due to pre.. >>> > > i is now 10 . >>> > > output i*i(10*10) >>> > > i=i+1 (due to post inc., it inc. the value after the output) >>> > > i is now 11 >>> >>> > > 3. ++i*i++ >>> > > right to left evaluation, but post inc. increases value only >>> > > after >>> > output.. >>> > > coming to ++i in the expn., i inc. to 12 >>> > > output: 12*12 >>> > > i=i+1(due to postinc.) >>> > > i is now 13 >>> >>> > > 4. ++i*++i >>> > > both pre inc operators, order of evaluation doesnt ,matter: >>> > > i=i+1 >>> > > i=i+1 >>> > > output: 15*15 >>> >>> > > i finishes at 15 >>> >>> > > Hence the output: >>> > > 49 >>> > > 100 >>> > > 144 >>> > > 225 >>> >>> > > I think i made it clear.. >>> > > Feel free to point any loopholes.. >>> >>> > > Thanks. >>> >>> > > On 8/3/11, ankit sambyal <[email protected]> wrote: >>> >>> > > > Its compiler dependent. Acc. to the C standard an object's stored >>> > > > value >>> > can >>> > > > be modified only once in an expression. >>> >>> > > > -- >>> > > > 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. >>> >>> > -- >>> > 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. >> >> -- >> 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. >> >> > -- 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.
