Michael White wrote: > > > Which compiler are you using? > > Every compiler I know reads within ( ) first, and then from right to > the left. The only time the code I present would have a problem was if > the 'a' was a zero (0), because it will crash if you try to divide > anything by '0'. > > --- On Thu, 7/16/09, Paul Herring <[email protected] > <mailto:pauljherring%40gmail.com>> wrote: > > From: Paul Herring <[email protected] > <mailto:pauljherring%40gmail.com>> > Subject: Re: [c-prog] I am not agree with u. > To: [email protected] <mailto:c-prog%40yahoogroups.com> > Date: Thursday, July 16, 2009, 2:04 PM > > On Thu, Jul 16, 2009 at 4:54 PM, Michael > White<[email protected] <mailto:michael_white2%40yahoo.com>> wrote: > > A way to help determine how you want the following scenario to play out > > is to surround the piece of code you want to be sure is enacted on > first with ( ). > > > > For example... > > > > int b = a / (++a); > > > > This will remove all doubt as to what will happen. > > No it won't. Adding parenthesis does absolutely nothing in this situation. > > It's still invalid code, because either the numerator or denominator > can be examined first, leading to two different possible answers. > > -- > PJH > > http://shabbleland.myminicity.com/com > <http://shabbleland.myminicity.com/com> > http://www.chavgangs.com/register.php?referer=9375 > <http://www.chavgangs.com/register.php?referer=9375> > > ------------------------------------ > > To unsubscribe, send a blank message to > <mailto:[email protected] > <mailto:c-prog-unsubscribe%40yahoogroups.com>>.Yahoo! Groups Links > > [Non-text portions of this message have been removed] > > I believe Paul's point is that incrementing a like that will be done before the numerator is taken into account, which will give you 1 every time.
int a = 5; int b = a / (++a); (++a) will turn a into 6, and also return 6. Then you have 6 / 6, which yields 1. I believe it would be a different story if you were to use (a++) (you would actually get greater than one, which seems unexpected). int a = 5; int b = a / (a++) a++ would turn a into 6, and return 5. Then you have 6 / 5, which yields > 1. [Non-text portions of this message have been removed]
