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.

Reply via email to