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.

--- On Thu, 7/16/09, Paul Herring <[email protected]> wrote:

From: Paul Herring <[email protected]>
Subject: Re: [c-prog] I am not agree with u.
To: [email protected]
Date: Thursday, July 16, 2009, 10:43 AM

On Wed, Jul 15, 2009 at 8:38 AM, Nayera Khan<[email protected]> wrote:
> How it could be? is it possible after initializing a=5 ,6 could divided by 6 ,
> It could possible after dividing a by ++a,a will be six

Given

int a = 5;

and

int b = a / ++a;

You don't know (and should never assume) whether the compiler will look at:
 o  the 'a' first (and the '++a' second) or
 o  the '++a' first (and the 'a' second)

If it looks at the 'a' first, it will arrive at:

5/6

If it looks at the '++a' first it will arrive at:

6/6

Since this is integer arithmetic, the first returns 0 and the second returns 1.

Since this is C (or C++) and the compiler is allowed to choose which
of 'a' or '++a' is looked at first, the answer is indeterminable, and
thus the whole expression (and ones like it) should not be used in C
or C++ since you can not guarantee the answer.

What your other favourite language does with such expressions is
irrelevant here.

-- 
PJH

http://shabbleland.myminicity.com/com
http://www.chavgangs.com/register.php?referer=9375


------------------------------------

To unsubscribe, send a blank message to 
<mailto:[email protected]>.Yahoo! Groups Links





[Non-text portions of this message have been removed]

Reply via email to