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

Reply via email to