From: ashwin mittal [mailto:[EMAIL PROTECTED] 
>--- [EMAIL PROTECTED] wrote:
>> --- In [EMAIL PROTECTED], srikanth

I replied to this post from the web, mistakingly thinking it was a
recent post, apologies for bringing it up again - I did ask the
moderator to delete instead of approve my post, however it seems to have
escaped...

>> poojary <[EMAIL PROTECTED]> wrote:
>> > main()
>> > {
>> > int i=5;
>> > printf("%d%d%d%d%d",i++,i--,++i,--i,i);
>> > }
>> > 
>> >  
>> > what is the o/p and why?
>> 
>> Output may be anything and it would be correct. See:
>> <http://www.eskimo.com/~scs/C-faq/q3.1.html> and the
>> next few questions.
> 
>Hi all,
>
>The Printf expression is compile from Right to left...

'compiled' maybe, if only because the compiler may go serially through
the file (though The Standard has nothing to say on the matter)

>So starting from right,
>i,
>--i,
>++i,
>i--,
>i++
>
>the sequence goes like this....
>
>So 
>i = 5;
>--i = 4;
>++i = 5;
>i-- = 5;
>i++ = 4

This has nothing to do with whatever answer your instance of the program
comes up with.

>But the printf will display the output in that
>sequence in which it is demanded...
>i.e. from left to right...

No it isn't. The order of evaluation of the parameters to a function is
not defined. The comma separating parameters is not the comma operator,
it is merely a separator. The only thing that is guaranteed about the
expressions is that all of them will be evaluated by the time the
function (printf() in this case) is called.

The compiler and/or runtime is free to evaluate the parameters from the
left, right, or in any order that (to the untrained eye) doesn't make
any sense.

>i++,
>i--,
>++i,
>--i,
>i

So this is wrong. In the sense that this is not necessarily what will
happen.

>Accordingly the values are displayed as such...
>i.e 
>4 5 5 4 5

However, that happens to be one of the correct answers. As would '42',
'Hello World' or formatting your hard drive. Try looking at the link I
suggested, and that you quoted.

--
PJH

If Windows is the solution, can we please have the problem back?
unknown





Alderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12 
8JD, UK
Tel: +44(0)1454 294556 Fax: +44 (0)1454 299272

Website : www.alderley.com  Sales : [EMAIL PROTECTED] Service : [EMAIL 
PROTECTED]

This email and its contents are confidential and are solely for the use of the 
intended recipient. If you are not the original recipient you have received it 
in error and any use, dissemination, forwarding, printing or copying of this 
email is strictly prohibited. Should you receive this email in error please 
immediately notify [EMAIL PROTECTED]

This email has been scanned for viruses, however you should always scan emails 
with your own systems prior to opening.









------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/EbFolB/TM
--------------------------------------------------------------------~-> 

To unsubscribe : [EMAIL PROTECTED]

 
Yahoo! Groups Links

<*> To reply to this message, go to:
    
http://groups.yahoo.com/group/Programmers-Town/post?act=reply&messageNum=4895
    Please do not reply to this message via email. More information here:
    http://help.yahoo.com/help/us/groups/messages/messages-23.html

<*> To visit your group on the web, go to:  
    http://groups.yahoo.com/group/Programmers-Town/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to