Thread: [Dev-C++] Question about increment..
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Mani <man...@gm...> - 2012-09-20 16:54:29
|
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 |
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 |
From: Mani <man...@gm...> - 2012-09-20 18:08:52
|
Hi, But this is not right, if I understand precedence rules correctly.. ++ has higher precedence than addition.. your explanation seems to say that ++ is done after addition.. In Java, the same expression gives 8.., and I believe other C++ compilers also gave 8 (I heard from others; I have not tested this myself -- I did test what happens in Java myself). I am inclined to think this looks like a bug..?? thanks, murali. On Thu, Sep 20, 2012 at 1:04 PM, a.geo <aqu...@gm...> wrote: > 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 >> |
From: Mani <man...@gm...> - 2012-09-20 18:21:37
|
Thanks for all the comments.. I had posted to mingw-users mailing list as well, I had lots of good responses there (I had posted here w/o looking at those responses..) for those interested, you can see these at: http://sourceforge.net/mailarchive/forum.php?thread_name=5058E683.1010205%40users.sourceforge.net&forum_name=mingw-users thanks once again for your time. best, murali. On Thu, Sep 20, 2012 at 2:15 PM, Brothers, Robert <rob...@tq...> wrote: > Murali, > > I'm not a C++ programmer (use C# mostly), but I put your original code > into Visual Studio C++.net and it gave the c = 6 result as well. > > The code Mani offered ( ++a + ++b + a + b) gave the value of 10 (which I > tend to feel is understandable since the value of a and b are > incremented first then 2 + 3 + 2 + 3 = 10). > > If I write the code as: > > int a = 1, b = 2; > int c = a++ + b++; > c += a + b; > > I DO get 8 as the result. > > Also, in C#, your original code give 8 as you found in Java. > > As I said, I'm not a C++ programmer (I'm a EE not a programmer;^) > > Regards > Bob > > > > -----Original Message----- > From: Mani [mailto:man...@gm...] > Sent: Thursday, September 20, 2012 1:09 PM > To: a.geo > Cc: dev...@li... > Subject: Re: [Dev-C++] Question about increment.. > > Hi, > > But this is not right, if I understand precedence rules correctly.. > ++ has higher precedence than addition.. your explanation seems to say > that ++ is done after addition.. > > In Java, the same expression gives 8.., and I believe other C++ > compilers also gave 8 (I heard from others; I have not tested this > myself -- I did test what happens in Java myself). > > I am inclined to think this looks like a bug..?? > > thanks, murali. > > On Thu, Sep 20, 2012 at 1:04 PM, a.geo <aqu...@gm...> wrote: >> 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 > > |
From: Reid T. <Rei...@at...> - 2012-09-20 20:25:08
|
On Thu, 2012-09-20 at 12:54 -0400, Mani wrote: > 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 [16:06:54][94s] rthompso@raker2> ~ $ cat helloworld.c #include <stdio.h> #include <stdlib.h> int main(void) { int a = 1, b = 2; int c = a++ + b++ + a + b; printf("c is %d\n", c); a = 1; b = 2; c = ++a + ++b + a + b; printf("c is %d\n", c); return 0; } [16:07:01][0s] rthompso@raker2> ~ $ cat Hello.cs using System; class Program { static void Main() { int a = 1, b = 2; int c = a++ + b++ + a + b; Console.WriteLine(c); Console.WriteLine("Hello world!"); a = 1; b = 2; c = ++a + ++b + a + b; Console.WriteLine(c); Console.WriteLine("Hello world!"); a = 1; b = 2; c = a++ + b++; int d = c + a + b; Console.WriteLine(d); } } [16:07:26][0s] rthompso@raker2> ~ $ ./a.out c is 6 c is 10 [16:07:30][0s] rthompso@raker2> ~ $ mono Hello.exe 8 Hello world! 10 Hello world! 8 gcc C n++ -> increment after use > int a = 1, b = 2; > int c = a++ + b++ + a + b; c = 1 + 2 + 1 + 2 c = 6 ++n -> increment before use > int a = 1, b = 2; > int c = ++a + ++b + a + b; c = 2 + 3 + 2 + 3 c = 10 mcs csharp evidently creates an incremented copy and uses it with the original value > int a = 1, b = 2; > int c = a++ + b++ + a + b; c = 2 + 3 + 1 + 2 c = 8 ++n -> increment before use > int a = 1, b = 2; > int c = ++a + ++b + a + b; c = 2 + 3 + 2 + 3 c = 10 a = 1; b = 2; c = a++ + b++; int d = c + a + b; c = 5 d = 5 + 1 + 2 d = 8 |
From: Mani <man...@gm...> - 2012-09-21 01:08:30
|
I think I might argue with one point way below.. please scroll down.. On Thu, Sep 20, 2012 at 4:08 PM, Reid Thompson <Rei...@at...> wrote: > On Thu, 2012-09-20 at 12:54 -0400, Mani wrote: >> 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 > > [16:06:54][94s] rthompso@raker2> ~ > $ cat helloworld.c > #include <stdio.h> > #include <stdlib.h> > int main(void) > { > int a = 1, b = 2; > int c = a++ + b++ + a + b; > > printf("c is %d\n", c); > a = 1; > b = 2; > c = ++a + ++b + a + b; > > printf("c is %d\n", c); > > return 0; > > } > > [16:07:01][0s] rthompso@raker2> ~ > $ cat Hello.cs > using System; > > class Program > { > static void Main() > { > int a = 1, b = 2; > int c = a++ + b++ + a + b; > > Console.WriteLine(c); > Console.WriteLine("Hello world!"); > > a = 1; > b = 2; > c = ++a + ++b + a + b; > Console.WriteLine(c); > Console.WriteLine("Hello world!"); > > > a = 1; > b = 2; > c = a++ + b++; > int d = c + a + b; > > Console.WriteLine(d); > } > } > > [16:07:26][0s] rthompso@raker2> ~ > $ ./a.out > c is 6 > c is 10 > > [16:07:30][0s] rthompso@raker2> ~ > $ mono Hello.exe > 8 > Hello world! > 10 > Hello world! > 8 > > > gcc C > n++ -> increment after use >> int a = 1, b = 2; >> int c = a++ + b++ + a + b; > c = 1 + 2 + 1 + 2 > c = 6 > > ++n -> increment before use >> int a = 1, b = 2; >> int c = ++a + ++b + a + b; > c = 2 + 3 + 2 + 3 > c = 10 > > mcs csharp > evidently creates an incremented copy and uses it with the original > value >> int a = 1, b = 2; >> int c = a++ + b++ + a + b; > c = 2 + 3 + 1 + 2 > c = 8 >>>> BEGIN: Murali: How can you be sure that this is what happens.. I am inclined to believe what happens is: c = 1 + 2 + 2 + 3 c = 8 >>>> END: Murali > > ++n -> increment before use >> int a = 1, b = 2; >> int c = ++a + ++b + a + b; > c = 2 + 3 + 2 + 3 > c = 10 > > a = 1; > b = 2; > c = a++ + b++; > int d = c + a + b; > c = 5 > d = 5 + 1 + 2 > d = 8 > > |
From: Reid T. <rei...@at...> - 2012-09-21 01:51:00
|
On 9/20/2012 9:08 PM, Mani wrote: > I think I might argue with one point way below.. please scroll down.. > > On Thu, Sep 20, 2012 at 4:08 PM, Reid Thompson <Rei...@at...> wrote: >> On Thu, 2012-09-20 at 12:54 -0400, Mani wrote: >>> 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 >> [16:06:54][94s] rthompso@raker2> ~ >> $ cat helloworld.c >> #include <stdio.h> >> #include <stdlib.h> >> int main(void) >> { >> int a = 1, b = 2; >> int c = a++ + b++ + a + b; >> >> printf("c is %d\n", c); >> a = 1; >> b = 2; >> c = ++a + ++b + a + b; >> >> printf("c is %d\n", c); >> >> return 0; >> >> } >> >> [16:07:01][0s] rthompso@raker2> ~ >> $ cat Hello.cs >> using System; >> >> class Program >> { >> static void Main() >> { >> int a = 1, b = 2; >> int c = a++ + b++ + a + b; >> >> Console.WriteLine(c); >> Console.WriteLine("Hello world!"); >> >> a = 1; >> b = 2; >> c = ++a + ++b + a + b; >> Console.WriteLine(c); >> Console.WriteLine("Hello world!"); >> >> >> a = 1; >> b = 2; >> c = a++ + b++; >> int d = c + a + b; >> >> Console.WriteLine(d); >> } >> } >> >> [16:07:26][0s] rthompso@raker2> ~ >> $ ./a.out >> c is 6 >> c is 10 >> >> [16:07:30][0s] rthompso@raker2> ~ >> $ mono Hello.exe >> 8 >> Hello world! >> 10 >> Hello world! >> 8 >> >> >> gcc C >> n++ -> increment after use >>> int a = 1, b = 2; >>> int c = a++ + b++ + a + b; >> c = 1 + 2 + 1 + 2 >> c = 6 >> >> ++n -> increment before use >>> int a = 1, b = 2; >>> int c = ++a + ++b + a + b; >> c = 2 + 3 + 2 + 3 >> c = 10 >> >> mcs csharp >> evidently creates an incremented copy and uses it with the original >> value >>> int a = 1, b = 2; >>> int c = a++ + b++ + a + b; >> c = 2 + 3 + 1 + 2 >> c = 8 >>>>> BEGIN: Murali: > How can you be sure that this is what happens.. I am inclined to > believe what happens is: > c = 1 + 2 + 2 + 3 > c = 8 > >>>>> END: Murali >> ++n -> increment before use >>> int a = 1, b = 2; >>> int c = ++a + ++b + a + b; >> c = 2 + 3 + 2 + 3 >> c = 10 >> >> a = 1; >> b = 2; >> c = a++ + b++; >> int d = c + a + b; >> c = 5 >> d = 5 + 1 + 2 >> d = 8 >> >> ok -- you are most likely correct. |
From: Robert A. <ral...@gm...> - 2012-09-21 10:30:57
|
Hello, It's undefined in the standard.... the sub expressions can be calculated in any order.... ie... = a++ + b++ + a + b; a++ could be calculated before or after any of the following b++ , a , b, Since the side effects of the a++ and b++ change the value of the later it is undefined in C or C++ See also: http://en.wikipedia.org/wiki/Unspecified_behavior On Thu, Sep 20, 2012 at 9:50 PM, Reid Thompson <rei...@at...> wrote: > On 9/20/2012 9:08 PM, Mani wrote: >> I think I might argue with one point way below.. please scroll down.. >> >> On Thu, Sep 20, 2012 at 4:08 PM, Reid Thompson <Rei...@at...> wrote: >>> On Thu, 2012-09-20 at 12:54 -0400, Mani wrote: >>>> 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 >>> [16:06:54][94s] rthompso@raker2> ~ >>> $ cat helloworld.c >>> #include <stdio.h> >>> #include <stdlib.h> >>> int main(void) >>> { >>> int a = 1, b = 2; >>> int c = a++ + b++ + a + b; >>> >>> printf("c is %d\n", c); >>> a = 1; >>> b = 2; >>> c = ++a + ++b + a + b; >>> >>> printf("c is %d\n", c); >>> >>> return 0; >>> >>> } >>> >>> [16:07:01][0s] rthompso@raker2> ~ >>> $ cat Hello.cs >>> using System; >>> >>> class Program >>> { >>> static void Main() >>> { >>> int a = 1, b = 2; >>> int c = a++ + b++ + a + b; >>> >>> Console.WriteLine(c); >>> Console.WriteLine("Hello world!"); >>> >>> a = 1; >>> b = 2; >>> c = ++a + ++b + a + b; >>> Console.WriteLine(c); >>> Console.WriteLine("Hello world!"); >>> >>> >>> a = 1; >>> b = 2; >>> c = a++ + b++; >>> int d = c + a + b; >>> >>> Console.WriteLine(d); >>> } >>> } >>> >>> [16:07:26][0s] rthompso@raker2> ~ >>> $ ./a.out >>> c is 6 >>> c is 10 >>> >>> [16:07:30][0s] rthompso@raker2> ~ >>> $ mono Hello.exe >>> 8 >>> Hello world! >>> 10 >>> Hello world! >>> 8 >>> >>> >>> gcc C >>> n++ -> increment after use >>>> int a = 1, b = 2; >>>> int c = a++ + b++ + a + b; >>> c = 1 + 2 + 1 + 2 >>> c = 6 >>> >>> ++n -> increment before use >>>> int a = 1, b = 2; >>>> int c = ++a + ++b + a + b; >>> c = 2 + 3 + 2 + 3 >>> c = 10 >>> >>> mcs csharp >>> evidently creates an incremented copy and uses it with the original >>> value >>>> int a = 1, b = 2; >>>> int c = a++ + b++ + a + b; >>> c = 2 + 3 + 1 + 2 >>> c = 8 >>>>>> BEGIN: Murali: >> How can you be sure that this is what happens.. I am inclined to >> believe what happens is: >> c = 1 + 2 + 2 + 3 >> c = 8 >> >>>>>> END: Murali >>> ++n -> increment before use >>>> int a = 1, b = 2; >>>> int c = ++a + ++b + a + b; >>> c = 2 + 3 + 2 + 3 >>> c = 10 >>> >>> a = 1; >>> b = 2; >>> c = a++ + b++; >>> int d = c + a + b; >>> c = 5 >>> d = 5 + 1 + 2 >>> d = 8 >>> >>> > ok -- you are most likely correct. > > ------------------------------------------------------------------------------ > Got visibility? > Most devs has no idea what their production app looks like. > Find out how fast your code is with AppDynamics Lite. > http://ad.doubleclick.net/clk;262219671;13503038;y? > 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 |