e-Nagar

November 22, 2007

Can u get rid of this bug in the code below?

Filed under: Humor — Ankur Aggarwal @ 11:46 pm

/* add.c
* a simple C program
*/

#include <stdio.h>
#define LAST 10

int main()
{
int i, sum = 0;

for ( i = 1; i <= LAST; i++ )
{
sum += i;
} /*-for-*/
printf(“sum = %d\n”, sum);
return 0;
}

Forwarded by Savitha

16 Comments »

  1. that was kinda cool – refreshed my c skills a bit
    also cleaned my monitor off its layer of dust!

    Comment by Prax — November 23, 2007 @ 2:10 am

  2. this makes me wonder that even though we both interact a lot… i do not even know what profession are you engaged in

    Comment by Ankur Aggarwal — November 23, 2007 @ 2:15 am

  3. yes precisely even i dont have a clue

    Comment by Prax — November 23, 2007 @ 2:18 am

  4. there is an orkut link in http://enagar.com/about/ which will have a more or less detailed description about me

    Comment by Ankur Aggarwal — November 23, 2007 @ 2:28 am

  5. i was talkg about myself
    im a jack of all trades master of none

    Comment by Prax — November 23, 2007 @ 2:30 am

  6. This bug has a very easy solution, which works for all bugs really. You just deny its existence and say it is “Working according to the use case”. Matter closed :)

    Comment by Aditya — November 23, 2007 @ 2:13 pm

  7. Awesome !

    Comment by Voracious Blog Reader — November 23, 2007 @ 3:15 pm

  8. :) ) ya the classic ostrich story… bury the head and hope that the problem goes away

    Comment by Ankur Aggarwal — November 23, 2007 @ 3:16 pm

  9. Or as put forward by Mustrum Ridcully Archchancellor of the Unseen University
    The fastest way to deal with problems is to ignore them. If they are important enough someone will come to you with it rather than leaving a note.

    Comment by Anonymous — November 23, 2007 @ 4:15 pm

  10. @vbr…
    hey it has been a very long time since u have posted a ppost

    Comment by Ankur Aggarwal — November 25, 2007 @ 8:37 pm

  11. It may be that if the value of LAST is increased the code will not work as sum will exceed the maximum integer value allowed. This will happen even LAST is much less than the maximum integer.

    Otherwise I don’t think there is a clue. The issue is similar to the bug in JDK (resolved now) to find average of two integers.

    Comment by Paramanand — November 26, 2007 @ 10:23 am

  12. @param…
    Sir the post is posted under humor and refers to the gif image of an actual fly embedded between the code.

    Comment by Ankur Aggarwal — November 26, 2007 @ 10:29 am

  13. Nice ankur, I thought that it was related to the flying bug, but it looks like my proxy server has banned the gif and so it was not visible here. I therefore thought that there is something important other than humor.

    Comment by Paramanand — November 26, 2007 @ 1:45 pm

  14. That was cool!

    Comment by Vasuki — November 27, 2007 @ 4:32 am

  15. Hehe..perhaps you can tell me? I can’t find any mistake :P

    Comment by ruhi — November 27, 2007 @ 8:42 am

  16. Good one!

    Comment by Avinash — December 13, 2007 @ 2:39 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply.... we want your views

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 36 other followers