Re: Strange processing!!

Milind Mehendale <[email protected]> Wed, 15 Mar 2006 20:23:52 -0800 (PST)
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
Hello Anju

I tried your code on VC++ 6.0 and it gave me 22 when
a=5. I then tried with couple of more values ... e.g.
for a=8 it gave me b=31.

The reason is ..... when u say ++a + ++a + ++a,
compiler first calculates ++a + ++a.

In this case if a is 5 then ++a => 6 and one more ++a
makes a = 7 ...so (++a + ++a) => (7 + 7) => 14 and
then it goes for third ++a so 

14 + (++a) ..at this moment value of a is 7 ... so
first it will increast a (so it will become 8 now) and
then add .... so 14 + (++a) => 14 + (8) = > 22.

you can try for other values as well .... even on gcc
it gives 22. 

I tried this on VC++ 7.0 as well ... in that case I
got b = 24 ... here it calculaes ++a in all 3 exp.
(which ultimately makes a =8) and then simply adds it
3 times ... :)

Well ...I told u how it does that but I don't know why
it does that :D :D ..experts ...pls guide us ... :D

cheers
Milind


--- anuj gupta <[email protected]> wrote:

> Thanks for bothering Rick.
> First of all i would like to know the reason behind
> 22. There is an apparent funda behind both 21 and
> 24,
> but dont can't digest 22!!
> Moreover, i run the program on Turbo C++, so that
> might be the only factor responsible for the problem
> Anyways, thanks again.
> Take care-
> Anuj.
> 
> 
> 		
>
__________________________________________________________
> 
> Yahoo! India Matrimony: Find your partner now. Go to
> http://yahoo.shaadi.com
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/cppug/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/