freelanceprogrammers.org Forum Index » C

about increment


View user's profile Post To page top
srikipoojary Posted: Wed Dec 01, 2004 3:10 pm


Joined: 01 Dec 2004

Posts: 1
about increment
main(){int i=5;printf("%d%d%d%d%d",i++,i--,++i,--i,i);}
 
what is the o/p and why?

Yahoo! India Matrimony: Find your life partner
online.
Reply with quote
Send private message
View user's profile Post To page top
surejantony Posted: Wed Dec 01, 2004 6:55 pm


Joined: 01 Dec 2004

Posts: 1
about increment
main()
{
int i=5;
printf("%d%d%d%d%d",i++,i--,++i,--i,i);
}


 


what is the o/p and why?
 
 
Hello friend
 
I believe the output will be different on
various compilers. Since you are accessing the an operator and using a
operation on it at the same time, the compiler output will be varied. If anyone
has another opinion about this please do suggest.
 
Surej

Yahoo! India Matrimony: Find your life partner online.

To
unsubscribe : programmers-town-unsubscribe@yahoogroups.com
Reply with quote
Send private message
View user's profile Post To page top
rohillaram@... Posted: Thu Dec 02, 2004 10:29 am


Joined: 02 Dec 2004

Posts: 1
about increment
The answer will be 55545

Because the printf is a function and it will have the
arguments by stack rules.
The order of evaluation will be reverse
i
--i
++i
i--
i++

The post incremant operator are always evaluated in
next line , not in the same line.


regards

Ram Kumar
--- surej antony joseph <surejaj@...>
wrote:

> main()
> {
> int i=5;
> printf("%d%d%d%d%d",i++,i--,++i,--i,i);
> }
>
>
>
> what is the o/p and why?
>
>
>
>
>
> Hello friend
>
>
>
> I believe the output will be different on various
> compilers. Since you are
> accessing the an operator and using a operation on
> it at the same time, the
> compiler output will be varied. If anyone has
> another opinion about this
> please do suggest.
>
>
>
> Surej
>
>
>
<http://in.rd.yahoo.com/specials/mailtg/*http:/yahoo.shaadi.com/india-matrim
> ony/> Yahoo! India Matrimony: Find your life partner
> online
>
<http://in.rd.yahoo.com/specials/mailtg2/*http:/yahoo.shaadi.com/india-matri
> mony/> .
>
> To unsubscribe :
> programmers-town-unsubscribe@yahoogroups.com
>
>
>
>
>
>
>
>
> Yahoo! Groups Sponsor
>
>
>
> ADVERTISEMENT
>
>
<http://us.ard.yahoo.com/SIG=129rpd390/M=298184.5639630.6699735.3001176/D=gr
>
oups/S=1705006788:HM/EXP=1101980549/A=2434971/R=0/SIG=11eeoolb0/*http:/www.n
> etflix.com/Default?mqso=60185400> click here
>
>
>
>
<http://us.adserver.yahoo.com/l?M=298184.5639630.6699735.3001176/D=groups/S=
> :HM/A=2434971/rand=506291532>
>
>
>
> _____
>
> Yahoo! Groups Links
>
> * 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:
> Programmers-Town-unsubscribe@yahoogroups.com
>
<mailto:Programmers-Town-unsubscribe@yahoogroups.com?subject=Unsubscribe>
>
>
> * Your use of Yahoo! Groups is subject to the Yahoo!
> <http://docs.yahoo.com/info/terms/> Terms of
> Service.
>
>


=====
With thanks & regardsRam Kumar Rohilla1375 P , Sector
17c,GurgaonHaryana122001Phone 0124 - 6345666



__________________________________
Do you Yahoo!?
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
vivek_anand_... Posted: Thu Dec 02, 2004 3:47 pm


Joined: 02 Dec 2004

Posts: 1
about increment
but the ouput in TC compiler is 4 5 5 4 5  .the compiler takes the value of the arguments from right to left..
 
Vivek AgarwalSoftware EngineerNetworks-DivisonSasken Communication Technologies Limited,#690, Gold Hill Square,Hosur main road,Bommanhallli,Bangalore-560068 ,INDIAEmail: vagarwal@...Tel: + 91 80 56945000 extn:5514Mobile: +91 98860-85563Fax: + 91 80 56945333URL: www.sasken.com

----- Original Message -----
From: surej antony joseph
To: programmers-town@yahoogroups.com
Sent: Wednesday, December 01, 2004 6:25 PM
Subject: RE: (PT) about increment



main(){int i=5;printf("%d%d%d%d%d",i++,i--,++i,--i,i);}

 

what is the o/p and why?
 
 
Hello friend
 
I believe the output will be different on various compilers. Since you are accessing the an operator and using a operation on it at the same time, the compiler output will be varied. If anyone has another opinion about this please do suggest.
 
Surej
Yahoo! India Matrimony: Find your life partner online. To unsubscribe : programmers-town-unsubscribe@yahoogroups.comTo unsubscribe : programmers-town-unsubscribe@yahoogroups.com
"SASKEN RATED THE BEST EMPLOYER IN THE COUNTRY by the BUSINESS TODAY Mercer Survey 2004"


SASKEN BUSINESS DISCLAIMER
This message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email
Reply with quote
Send private message
View user's profile Post To page top
shyamala.vurubandi@... Posted: Mon Dec 06, 2004 3:18 pm


Joined: 06 Dec 2004

Posts: 1
about increment
int i=5;printf("%d%d%d%d%d",i++,i--,++i,--i,i);
actually when we give like this, it uses the stack. so it gives output from right to left as 4 5 5 4 5 

----- Original Message -----
From: vivek agarwal
To: programmers-town@yahoogroups.com
Sent: Thursday, December 02, 2004 3:17 PM
Subject: Re: (PT) about increment

but the ouput in TC compiler is 4 5 5 4 5  .the compiler takes the value of the arguments from right to left..
 
Vivek AgarwalSoftware EngineerNetworks-DivisonSasken Communication Technologies Limited,#690, Gold Hill Square,Hosur main road,Bommanhallli,Bangalore-560068 ,INDIAEmail: vagarwal@...Tel: + 91 80 56945000 extn:5514Mobile: +91 98860-85563Fax: + 91 80 56945333URL: www.sasken.com

----- Original Message -----
From: surej antony joseph
To: programmers-town@yahoogroups.com
Sent: Wednesday, December 01, 2004 6:25 PM
Subject: RE: (PT) about increment



main(){int i=5;printf("%d%d%d%d%d",i++,i--,++i,--i,i);}

 

what is the o/p and why?
 
 
Hello friend
 
I believe the output will be different on various compilers. Since you are accessing the an operator and using a operation on it at the same time, the compiler output will be varied. If anyone has another opinion about this please do suggest.
 
Surej
Yahoo! India Matrimony: Find your life partner online. To unsubscribe : programmers-town-unsubscribe@yahoogroups.comTo unsubscribe : programmers-town-unsubscribe@yahoogroups.comTo unsubscribe : programmers-town-unsubscribe@yahoogroups.com



"SASKEN RATED THE BEST EMPLOYER IN THE COUNTRY by the BUSINESS TODAY Mercer Survey 2004"SASKEN BUSINESS DISCLAIMERThis message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email
Reply with quote
Send private message
View user's profile Post To page top
sg7650 Posted: Tue Dec 07, 2004 12:51 am


Joined: 02 Jan 2005

Posts: 5
about increment
HI,


--- In Programmers-Town@yahoogroups.com, Ram Kumar Rohilla
<rohillaram@y...> wrote:
>
> The answer will be 55545

i think it should be 54545

> The order of evaluation will be reverse
> i
5 pushed to stack

> --i
4 pushed to stack

> ++i
5 pushed to stack

> i--
4 pushed to stack as i-- will be evaluated and after that value is
stored

> i++
5 pushed to stack

>
> The post incremant operator are always evaluated in
> next line , not in the same line.
well if this is the case then post decrement operator should also be
evaluated in the next line and not on same line. and then the result
should be 45545


Bye
Sumit

>
>
> regards
>
> Ram Kumar
> --- surej antony joseph <surejaj@a...>
> wrote:
>
> > main()
> > {
> > int i=5;
> > printf("%d%d%d%d%d",i++,i--,++i,--i,i);
> > }
> >
> >
> >
> > what is the o/p and why?
> >
> >
> >
> >
> >
> > Hello friend
> >
> >
> >
> > I believe the output will be different on various
> > compilers. Since you are
> > accessing the an operator and using a operation on
> > it at the same time, the
> > compiler output will be varied. If anyone has
> > another opinion about this
> > please do suggest.
> >
> >
> >
> > Surej
> >
> >
> >
>
<http://in.rd.yahoo.com/specials/mailtg/*http:/yahoo.shaadi.com/india
-matrim
> > ony/> Yahoo! India Matrimony: Find your life partner
> > online
> >
>
<http://in.rd.yahoo.com/specials/mailtg2/*http:/yahoo.shaadi.com/indi
a-matri
> > mony/> .
> >
> > To unsubscribe :
> > programmers-town-unsubscribe@yahoogroups.com
> >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Sponsor
> >
> >
> >
> > ADVERTISEMENT
> >
> >
>
<http://us.ard.yahoo.com/SIG=129rpd390/M=298184.5639630.6699735.30011
76/D=gr
> >
>
oups/S=1705006788:HM/EXP=1101980549/A=2434971/R=0/SIG=11eeoolb0/*http
:/www.n
> > etflix.com/Default?mqso=60185400> click here
> >
> >
> >
> >
> <http://us.adserver.yahoo.com/l?
M=298184.5639630.6699735.3001176/D=groups/S=
> > :HM/A=2434971/rand=506291532>
> >
> >
> >
> > _____
> >
> > Yahoo! Groups Links
> >
> > * 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:
> > Programmers-Town-unsubscribe@yahoogroups.com
> >
> <mailto:Programmers-Town-unsubscribe@yahoogroups.com?
subject=Unsubscribe>
> >
> >
> > * Your use of Yahoo! Groups is subject to the Yahoo!
> > <http://docs.yahoo.com/info/terms/> Terms of
> > Service.
> >
> >
>
>
> =====
> With thanks & regardsRam Kumar Rohilla1375 P , Sector
17c,GurgaonHaryana122001Phone 0124 - 6345666
>
>
>
> __________________________________
> Do you Yahoo!?
> The all-new My Yahoo! - What will yours do?
> http://my.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
sg7650 Posted: Tue Dec 07, 2004 12:58 am


Joined: 02 Jan 2005

Posts: 5
about increment
Hi,

some corrections in the last mail.
The post increment & decrement operators are evaluated after the
value is stored in stack.
So the value will be 45545 instead of 54545

i am sorry, my fault

Bye
Sumit

--- In Programmers-Town@yahoogroups.com, Ram Kumar Rohilla
<rohillaram@y...> wrote:
>
> The answer will be 55545
>
> Because the printf is a function and it will have the
> arguments by stack rules.
> The order of evaluation will be reverse
> i
> --i
> ++i
> i--
> i++
>
> The post incremant operator are always evaluated in
> next line , not in the same line.
>
>
> regards
>
> Ram Kumar
> --- surej antony joseph <surejaj@a...>
> wrote:
>
> > main()
> > {
> > int i=5;
> > printf("%d%d%d%d%d",i++,i--,++i,--i,i);
> > }
> >
> >
> >
> > what is the o/p and why?
> >
> >
> >
> >
> >
> > Hello friend
> >
> >
> >
> > I believe the output will be different on various
> > compilers. Since you are
> > accessing the an operator and using a operation on
> > it at the same time, the
> > compiler output will be varied. If anyone has
> > another opinion about this
> > please do suggest.
> >
> >
> >
> > Surej
> >
> >
> >
>
<http://in.rd.yahoo.com/specials/mailtg/*http:/yahoo.shaadi.com/india
-matrim
> > ony/> Yahoo! India Matrimony: Find your life partner
> > online
> >
>
<http://in.rd.yahoo.com/specials/mailtg2/*http:/yahoo.shaadi.com/indi
a-matri
> > mony/> .
> >
> > To unsubscribe :
> > programmers-town-unsubscribe@yahoogroups.com
> >
> >
> >
> >
> >
> >
> >
> >
> > Yahoo! Groups Sponsor
> >
> >
> >
> > ADVERTISEMENT
> >
> >
>
<http://us.ard.yahoo.com/SIG=129rpd390/M=298184.5639630.6699735.30011
76/D=gr
> >
>
oups/S=1705006788:HM/EXP=1101980549/A=2434971/R=0/SIG=11eeoolb0/*http
:/www.n
> > etflix.com/Default?mqso=60185400> click here
> >
> >
> >
> >
> <http://us.adserver.yahoo.com/l?
M=298184.5639630.6699735.3001176/D=groups/S=
> > :HM/A=2434971/rand=506291532>
> >
> >
> >
> > _____
> >
> > Yahoo! Groups Links
> >
> > * 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:
> > Programmers-Town-unsubscribe@yahoogroups.com
> >
> <mailto:Programmers-Town-unsubscribe@yahoogroups.com?
subject=Unsubscribe>
> >
> >
> > * Your use of Yahoo! Groups is subject to the Yahoo!
> > <http://docs.yahoo.com/info/terms/> Terms of
> > Service.
> >
> >
>
>
> =====
> With thanks & regardsRam Kumar Rohilla1375 P , Sector
17c,GurgaonHaryana122001Phone 0124 - 6345666
>
>
>
> __________________________________
> Do you Yahoo!?
> The all-new My Yahoo! - What will yours do?
> http://my.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
shabble Posted: Fri Dec 24, 2004 5:15 pm


Joined: 29 Dec 2004

Posts: 31
about increment
--- In Programmers-Town@yahoogroups.com, srikanth poojary
<srikipoojary@y...> 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.
Reply with quote
Send private message
View user's profile Post To page top
ashwin_mittal26 Posted: Mon Dec 27, 2004 10:49 am


Joined: 27 Dec 2004

Posts: 14
about increment
--- pherring@... wrote:

>
>
> --- In Programmers-Town@yahoogroups.com, srikanth
> poojary
> <srikipoojary@y...> 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...
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


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

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


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


Regards,
Ashwin Mittal.



__________________________________
Do you Yahoo!?
Send a seasonal email greeting and help others. Do good.
http://celebrity.mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
deo31 Posted: Tue Dec 28, 2004 10:16 am


Joined: 31 Dec 2004

Posts: 5
about increment
i thgink the answer should be:
 
4 5 5 4 5.
any way isn`t it the answer?ashwin mittal <ashwin_mittal26@...> wrote:
--- pherring@... wrote:> > > --- In Programmers-Town@yahoogroups.com, srikanth> poojary> <srikipoojary@y...> 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...So starting from right,i,--i,++i,i--,i++the sequence goes like this....So i = 5;--i = 4;++i = 5;i-- = 5;i++ = 4But the printf
will display the output in thatsequence in which it is demanded...i.e. from left to right...i++,i--,++i,--i,iAccordingly the values are displayed as such...i.e 4 5 5 4 5Regards,Ashwin Mittal.            __________________________________ Do you Yahoo!? Send a seasonal email greeting and help others. Do good. http://celebrity.mail.yahoo.comTo unsubscribe : programmers-town-unsubscribe@yahoogroups.com
Do you Yahoo!? The all-new My Yahoo! – What will yours do?
Reply with quote
Send private message
View user's profile Post To page top
ashwin_mittal26 Posted: Tue Dec 28, 2004 3:08 pm


Joined: 27 Dec 2004

Posts: 14
about increment
Hi Deo...
try to use bottom pasting in future...
--- deo sharma <deo31@...> wrote:

> i thgink the answer should be:
>
> 4 5 5 4 5.
> any way isn`t it the answer?
>
> ashwin mittal <ashwin_mittal26@...> wrote:
>
>
> --- pherring@... wrote:
>
> >
> >
> > --- In Programmers-Town@yahoogroups.com, srikanth
> > poojary
> > <srikipoojary@y...> 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...
> 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
>
>
> But the printf will display the output in that
> sequence in which it is demanded...
> i.e. from left to right...
>
> i++,
> i--,
> ++i,
> --i,
> i
>
>
> Accordingly the values are displayed as such...
> i.e
> 4 5 5 4 5
>
>
> Regards,
> Ashwin Mittal.
>


Yah this is the answer it should be 4 5 5 4 5...

Just read the above paragraph...


regards,
Ashwin Mittal.


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
friend_007_hi Posted: Tue Dec 28, 2004 6:18 pm


Joined: 28 Dec 2004

Posts: 1
about increment
pherring@... wrote:

--- In Programmers-Town@yahoogroups.com, srikanth poojary<srikipoojary@y...> wrote:> main()> {> int i=5;> printf("%d%d%d%d%d",i++,i--,++i,--i,i);> }> >  > what is the o/p and why?
Hi,
The o/p will be :
4,5,5,4,5
Finally the value of i will be 5.
This is becoz printf process from right to left.
printf("%d%d%d%d%d",i++,i--,++i,--i,i);
First the rightmost one : i =5
--i => 4
++i => 5
then i-- => first print i that is 5, then decrement,
i++ =>  first print i that is 4, then increment.
Hence, the final value of i=5.
Regards,
KanagaOutput may be anything and it would be correct. See:<http://www.eskimo.com/~scs/C-faq/q3.1.html> and the next few questions.To unsubscribe : programmers-town-unsubscribe@yahoogroups.com

Yahoo! India Matrimony: Find your life partner
online.
Reply with quote
Send private message
View user's profile Post To page top
shabble Posted: Wed Dec 29, 2004 2:36 pm


Joined: 29 Dec 2004

Posts: 31
about increment
From: ashwin mittal [mailto:ashwin_mittal26@...]
>--- pherring@... wrote:
>> --- In Programmers-Town@yahoogroups.com, 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 <srikipoojary@y...> 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 : sales@... Service :
service@...

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 it@...

This email has been scanned for viruses, however you should always scan emails
with your own systems prior to opening.
Reply with quote
Send private message
View user's profile Post To page top
n_mkumaran Posted: Thu Dec 30, 2004 9:57 am


Joined: 30 Dec 2004

Posts: 1
about increment
Hi guys,
 
 
I have some doubt about Typedef and Swpping pointers..
 
Why we r using typedef for stucture...Ex.
 
typedef struct muthu{
int a;
int b;
}good;
 
void main()
{
good *a1;
 
a1= (good*) mallloc(muthu);
 
}
 
 
My question is y we are using typedef for structre is there any particular use?
 
 
2. How we can swap the pointer variable without third variable;
 
 
 
 
 
 
Paul Herring <pherring@...> wrote:
From: ashwin mittal [mailto:ashwin_mittal26@...] >--- pherring@... wrote:>> --- In Programmers-Town@yahoogroups.com, srikanthI replied to this post from the web, mistakingly thinking it was arecent post, apologies for bringing it up again - I did ask themoderator to delete instead of approve my post, however it seems to haveescaped...>> poojary <srikipoojary@y...> 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 throughthe 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++ = 4This has nothing to do with whatever answer your instance of the programcomes 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 isnot defined. The comma separating parameters is not the comma operator,it is merely a separator. The only thing that is guaranteed about theexpressions is that all
of them will be evaluated by the time thefunction (printf() in this case) is called.The compiler and/or runtime is free to evaluate the parameters from theleft, right, or in any order that (to the untrained eye) doesn`t makeany sense.>i++,>i--,>++i,>--i,>iSo this is wrong. In the sense that this is not necessarily what willhappen.>Accordingly the values are displayed as such...>i.e >4 5 5 4 5However, that happens to be one of the correct answers. As would `42`,`Hello World` or formatting your hard drive. Try looking at the link Isuggested, and that you quoted.--PJHIf Windows is the solution, can we please have the problem back?unknownAlderley plc, Arnolds Field Estate, The Downs, Wickwar, Gloucestershire, GL12 8JD, UKTel: +44(0)1454 294556 Fax: +44 (0)1454 299272Website : www.alderley.com  Sales :
sales@... Service : service@...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 it@...This email has been scanned for viruses, however you should always scan emails with your own systems prior to opening.To unsubscribe : programmers-town-unsubscribe@yahoogroups.com
Do you Yahoo!? Send holiday email and support a worthy cause. Do good.
Reply with quote
Send private message
View user's profile Post To page top
sflam108 Posted: Tue Jan 04, 2005 2:07 am


Joined: 25 Jul 2003

Posts: 48
about increment
Reply embedded...

> -----Original Message-----
> From: ashwin mittal [mailto:ashwin_mittal26@...]
> Sent: Sunday, December 26, 2004 10:50 PM
> To: Programmers-Town@yahoogroups.com
> Subject: Re: (PT) Re: about increment
> > --- In Programmers-Town@yahoogroups.com, srikanth
> > poojary
> > <srikipoojary@y...> wrote:
> > > main()
> > > {
> > > int i=5;
> > > printf("%d%d%d%d%d",i++,i--,++i,--i,i);
> > > }
> > >
> > >
> > > what is the o/p and why?
> >
> Hi all,
>
> The Printf expression is compile from Right to left...

You`re totally wrong here. The language does not specify any particular
argument passing order.

> So starting from right,
> i,
> --i,
> ++i,
> i--,
> i++
> the sequence goes like this....

Function arguments are not evaluated in any particular order either. There
is no "sequence" for evaluation of function arguments.

> So
> i = 5;
> --i = 4;
> ++i = 5;
> i-- = 5;
> i++ = 4

Again, wrong. There is no sequence point when evaluating the argument. So
after the first `i++`, the value of `i` is undetermined until the next
sequence point is reached (that is at the time just before the function
call).

Because of the undefined behavior, the entire statement is undefined.

If you do not know what a sequence point is and what classified as undefined
behavior, you don`t know enough about C.

Shyan
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help