RE: Strange processing!!

Alain Gurrea <[email protected]> Tue, 14 Mar 2006 06:27:31 -0800 (PST)
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
Anuj,

That sounds weird, Your 1st & 2nd approach should
yield the same result. What sort of c/c++ compiler
have you use? it might be helpful to know the behavior
of your c/c++ compiler.

Normally, when performing small task operating on
numbere i usually do it using a C/C++ manifest
constants. 

Ex.)

#define TUPLE_a(x, y)   (             \
                           (x  = ++y),\
                           (x += ++y),\
                           (x += ++y) \
                        )

so, if y, initially has a value of 5 expanding this
macro yields to 21 as the result of the ++ operation.


Regards,
Alain

Software Engineer
Lexmark R&D Corp.
Cebu Philippines.




--- Viorel ANUSCA <[email protected]> wrote:

> Hi Anuj,
>    
>   that it is beaucause:
>    
>    
>     –++n increments n before its value is used 
>   
> 
>    
>   and you have: b = x1+x2+x3 = 6+7+8 = 21
>    
>   Best,
>   Viorel
>   
> 
> anuj gupta <[email protected]> a écrit :
>   Hi All,
> This is Anuj,an MCA std from India.
> I tried the following 2 progs, both resulted in
> different outputs. But i don't understand the REASON
> behind them. 
> 
> 1. 
> int a=5, b = ++a + ++a + ++a;
> printf("%d",b);
> OUTPUT :- 21
> 
> 2.
> int a=5, b;
> b = ++a + ++a + ++a;
> printf("%d",b);
> OUTPUT :- 54
> 
> Even if i use Macro expansion instead of writing the
> whole expression, even then the result is same.
> If anyone out there can help me out it'll be a big
> help.Thank you.
> 
> 
>             
>
__________________________________________________________
> 
> Yahoo! India Matrimony: Find your partner now. Go to
> http://yahoo.shaadi.com
> 
> 
> 
> 
>   SPONSORED LINKS 
>         Programming languages   C programming
> language   Computer programming languages 
>     
> ---------------------------------
>   YAHOO! GROUPS LINKS 
> 
>     
>     Visit your group "cppug" on the web.
>     
>     To unsubscribe from this group, send an email
> to:
>  [email protected]
>     
>     Your use of Yahoo! Groups is subject to the
> Yahoo! Terms of Service. 
> 
>     
> ---------------------------------
>   
> 
> 
> 
> 		
> ---------------------------------
>  Nouveau : téléphonez moins cher avec Yahoo!
> Messenger ! Découvez les tarifs exceptionnels pour
> appeler la France et l'international.Téléchargez la
> version beta.
> 
> [Non-text portions of this message have been
> removed]
> 
> 


__________________________________________________
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/