Re: Strange processing!!
Matthias Wolpers <[email protected]> Sat, 18 Mar 2006 14:18:15 +0100
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
> > Message: 2 > Date: Fri, 17 Mar 2006 14:26:26 +0000 (GMT) > From: anuj gupta <[email protected]> > Subject: Re: Strange processing!! > > Hello Milind, > First of all i want to tell you that my name is Anuj, > not Anju... > Well, thanks for giving the reason behind the value > 22. > Another point is that which statement exactly did you > run on VC++ : > int b= ++a + ++a + ++a; > OR > int b; > b=++a + ++a + ++a; > > In TurboC++, the 2nd case produces the output 24, > while the first gives 21 (8+7+6). > But the reason behind 22 is still not very clear, it gets better and better: i tried this on a mac (ie gcc 33.whatever) : #include <iostream> int main (int argc, char * const argv[]) { int a1 = 5; int a2 = 5; int a3 = 5; int b1 = (((++a1) + (++a1)) + (++a1)); std::cout << "int b1 = (((++a1) + (++a1)) + (++a1)); gives " << b1 << " and a1 = " << a1 << std::endl; int b2 = ((++a2) + (++a2)); std::cout << "int b2 = ((++a2) + (++a2)); gives " << b2 << " and a2 = " << a2 << std::endl; int b3 = (++a3) ; std::cout << "int b3 = (++a3); gives " << b3 << " and a3 = " << a3 << std::endl; return 0; } and received this for my trouble: int b1 = (((++a1) + (++a1)) + (++a1)); gives 22 and a1 = 8 int b2 = ((++a2) + (++a2)); gives 14 and a2 = 7 int b3 = (++a3); gives 6 and a3 = 6 So, by all appearances there is need for a explaanation for a summand of 1 for b1 and b2. And there is a perfectly sensible b3 that behaves as expected. Insights, anybody? mats > i > mean why does it calculate the sum for two values > only? > > Can it be like an overloaded + operator -> > Calculates the sum of 2 values and adds it to the > third value. > > Another major doubt is that afterall why does it > processes the 2 statements differently in Turbo? > > Anyways, thanks for showing interest to all of you > folks. > Take care- > Anuj. > > > > > __________________________________________________________ > Yahoo! India Matrimony: Find your partner now. Go to http:// > yahoo.shaadi.com > > > ______________________________________________________________________ > __ > ______________________________________________________________________ > __ > > > > ---------------------------------------------------------------------- > -- > Yahoo! Groups Links > > > > > ---------------------------------------------------------------------- > -- > > > > > [Non-text portions of this message have been removed] 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/