Re: Strange processing!!
Benouareth Abdallah <[email protected]> Tue, 14 Mar 2006 23:30:01 -0800 (PST)
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
Hi Rick with Borland C++ Builder setting a=5 and b= ++a + ++a + ++a; I get b=24 because the last value of a is 8 and b will be evaluted after three incrementation of a; Best regards --- Rick <[email protected]> wrote: > Weird! I ran the same program, and also go 22 as a > result (both times). > > I use Windows XP and MSVC++ 6.0 > > NB: The ":-" is used frequently in Europe and the > UK where, in the US, we only use ":". So he was > specifying the result as 21, not -21. > > ~Rick > At 2006-03-14 09:46 AM, you wrote: > > >Hi Viorel, > >Look at Anuj's problem again: In one situation he > is initializing b, in > >the other the > >same expression is used to change an already > initialized b. Both use the > >expression > > > >++a + ++a + ++a > >which with a starting at 5 should equal 6 + 7 + > 8...so why in the second > >example > >is b set to 54? (Anuj you show the outputs as :-21 > and :-54 are yours being > >printed out as negative numbers?) > > > >Just a sec, lemme write a short program myself and > see if I have the > >same problem as > >Anuj... > > > > > >=================== > >void first(void) { > > > >int a = 5, b= ++a + ++a + ++a; > > > >printf("first %d \n",b); > >} > > > >void second(void) { > >int a = 5, b=0; > > > >b = ++a + ++a + ++a; > >printf("second %d \n",b); > >} > > > > > >int main (void) { > > > >first(); > >second(); > > > >return 0; > >} > >=================== > > > >When compiled and run I get: > > > >first 22 > >second 22 > > > >in both gcc under linux (slackware 3.6) and windows > 98 (Microsoft visual > >c/c++ v6.0) > >well at least I get the same number.. 22? > > > > > > > > > >Viorel ANUSCA 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] > > > > > > > > > > > > SPONSORED LINKS > > > Programming languages > > > > > > <http://groups.yahoo.com/gads?t=ms&k=Programming+languages&w1=Programming+languages&w2=C+programming+language&w3=Computer+programming+languages&c=3&s=91&.sig=vTY0ZkEm4qRK5cUrEO3rcw> > > > > > > C programming language > > > > > > <http://groups.yahoo.com/gads?t=ms&k=C+programming+language&w1=Programming+languages&w2=C+programming+language&w3=Computer+programming+languages&c=3&s=91&.sig=y09Gn12DCRYk7z9IXIkj5g> > > > > > > Computer programming languages > > > > > > <http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=Programming+languages&w2=C+programming+language&w3=Computer+programming+languages&c=3&s=91&.sig=dTMHM8wy9X__0zEfL1ff2Q> > > > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > YAHOO! GROUPS LINKS > > > > > > * Visit your group "cppug > <http://groups.yahoo.com/group/cppug>" > > > on the web. > > > * To unsubscribe from this group, send an > email to: > > > [email protected] > > > > <mailto:[email protected]?subject=Unsubscribe> > > > * Your use of Yahoo! Groups is subject to > the Yahoo! Terms of > > > Service > <http://docs.yahoo.com/info/terms/>. > > > > > > > === message truncated === __________________________________________________ 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/