Re: [Dev-C++] Question about increment..
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: a.geo <aqu...@gm...> - 2012-09-20 17:06:49
|
Change prefix by postfix... : D 2012/9/20 a.geo <aqu...@gm...> > Well, you really are doing the next > > int a = 1, b = 2; > int c = a + b + a + b; > a++; > b++; > This is why you get 6, remember the ++ is a prefix in this case, then, is > executed NEXT to the expression. > > int c = ++a + ++b + a + b; > Well, if this compile correctly, give you the 8 value, because > > int a = 1, b = 2; > ++a; > ++b; > int c = a + b + a + b; > > > 2012/9/20 Mani <man...@gm...> > >> Hi, >> >> I recently to try some toy things in DevC++ (version I am using is >> 4.9.9.2) >> >> The code I had was this: >> >> int a = 1, b = 2; >> int c = a++ + b++ + a + b; >> >> cout << "a = " << a << endl; >> cout << "b = " << b << endl; >> cout << "c = " << c << endl; >> >> I expected the c value to be 8 (by operator precedence, ++ has higher >> precedence than +, so do in order: >> a++, then b++ >> then do (a++ + b++) >> then add the previous result and a >> then add the previous result and b >> >> but the answer I got was 6.. >> >> what might be the reason for this..?? >> >> thanks, murali >> >> >> ------------------------------------------------------------------------------ >> Everyone hates slow websites. So do we. >> Make your web apps faster with AppDynamics >> Download AppDynamics Lite for free today: >> http://ad.doubleclick.net/clk;258768047;13503038;j? >> http://info.appdynamics.com/FreeJavaPerformanceDownload.html >> _______________________________________________ >> Dev-cpp-users mailing list >> Dev...@li... >> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users >> > > > > -- > Cesar De la Cruz Rojas > > *La mision de un buen soldado, no es morir por su patria, sino, lograr > que el soldado enemigo muera por la suya...* > * > ----------------------------------------------------------------------------- > * > Sennior Software Engineer > > ----------------------------------------------------------------------------- > Follow me in Facebook : http://www.facebook.com/aquiles.geo > Twitter http://twitter.com/ageo > Picture blog http://ageo.deviantart.com > > -- Cesar De la Cruz Rojas *La mision de un buen soldado, no es morir por su patria, sino, lograr que el soldado enemigo muera por la suya...* * ----------------------------------------------------------------------------- * Sennior Software Engineer ----------------------------------------------------------------------------- Follow me in Facebook : http://www.facebook.com/aquiles.geo Twitter http://twitter.com/ageo Picture blog http://ageo.deviantart.com |