Nayera Khan 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 

"It is also possible the core of the earth is made of cheese.  We just 
won't know until we get there."

It is also possible that your hard drive will be wiped for writing code 
like this.  I'm waiting for some compiler author to get the brilliant 
idea to make undefined behavior like this equate to a hard drive wipe. 
As your data is wiped off your hard drive with a message on your screen 
stating you write lousy code and that the current action is ANSI 
C++-compliant, you suddenly realize that discussions like these are moot 
points and you would then proceed change your ways to carefully write 
code that is easy to maintain, well-indented, with clear, 
easy-to-understand, in-context comments.

But, alas, since that will likely never happen (bummer), you will have 
to do the next best thing:  Write code such that the next person who has 
to maintain it is a serial killer who knows where you sleep.  So now ask 
yourself, which is less likely to get you killed by said cereal killer:

c = a / (a + 1);
a++;

Or:

c = a / ++a;

And then code accordingly.

> ________________________________
> From: Paul Herring <[email protected]>
> To: [email protected]
> Sent: Tuesday, July 14, 2009 10:12:10 PM
> Subject: Re: [c-prog] how to solve it
> 
> On Tue, Jul 14, 2009 at 5:21 AM, anurag JAIN <informanuragjain@ yahoo.com> 
> wrote:
>> Hi,
>>
>> Initially the value of a is 5.
>>
>> c=a/++a; means
>> c= 5/6
> 
> No it doesn't. It's permissible for the compiler to _also_ interpret it as:
> c = 6/6
> 
>> ; so C=0;
> 
> .... so that's wrong.
> 
> Neither method is wrong, and because both are valid, the construct
> 'a/++a' shouldn't be used in C because it is not well defined.
> 
>> d=++a/a++; means
>> d= 7/7;
> 
> No it doesn't. Another permissible interpretation is
> 
> d = 7/6
> 
> --
> PJH



-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to