freelanceprogrammers.org Forum Index » C
Re: about increment- SHYAN PLEASE SEE THIS
Joined: 05 Jan 2005
Posts: 1
Re: about increment- SHYAN PLEASE SEE THIS
hi,
i think there is an order of evaluation, called "ASSOCIATIVITY(of operators- see kernighan and ritchie)". In other words it is order or scanning (left-right or right -left) and order of execution(precedence).
i still have litle knowledge, as i found it confusing.
TRY TO JUSTIFY THE OUTPUT OF THE PROGRAM BELOW:-
void temp(){ int x; x=5; printf("%d,%d,%d,%d,%d
",++x,++x,--x,x,x);}
// OUTPUT 6,5,4,5,5
bye
ankush.
Shyan Lam <sflam@...> wrote:
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 particularargument 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. Thereis no "sequence" for evaluation of function arguments.> So> i = 5;> --i = 4;> ++i = 5;> i-- = 5;> i++ = 4Again, wrong. There is no sequence point when evaluating the argument. Soafter the first `i++`, the value of `i` is undetermined until the nextsequence point is reached (that is at the time just before the functioncall).Because of the undefined behavior, the entire statement is undefined. If you do not know what a sequence point is and what classified as undefinedbehavior, you don`t know enough about C. Shyan
Yahoo! India Matrimony: Find your life partner
online.
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
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.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







