FAQs about Bugs and Debugging

Your program runs and links without error messages, but...

My program appears to be running, but the output isn't right, and sometimes it does something weird. What's wrong?

No telling! Time to debug your program.
Read How to Debug.

I know my program is working correctly, and it produces output that exactly matches the sample, but it doesn't get any other points. What's wrong with the autograder?

Remember that you can say your program produces the correct output only if you have used a file-comparison utility to show that your output exactly matches the sample, byte-for-byte exactly as determined by a computer program, not by human eyeball scanning a page at 3:00 AM. Read the information about how the autograder compares outputs, and double-check. Follow our advice about how to compare files.

Almost always, we've discovered that this sort of problem was a result of definite bugs in your program, not the autograder. This can happen easily if you didn't seriously and systematically test the program before submitting it. The best assumption is that your program is full of bugs, and you just haven't found them yet.

Of course, if you really are stumped, ask us for help. We are always willing to help you debug your program, and we will check the autograder if it does indeed look suspicious. But chances are that the problem is in your code, so it's always more productive to suspect it first, not the autograder.

My program produces output that exactly matches the sample, but the autograder fails it on the same sample. What can I do?


My program runs fine, but when I run it in g++ or send it to the autograder, it crashes or loops or gets no points.

This sort of problem can arise if you have depended on non-standard or undefined behavior of the language or a library facility. It can be due to a misaddressing error (see below).

But we have seen many cases where a problem like this was due to an uninitialized variable. The value of such a variable is undefined - it could be anything. But the variable might happen to have the "right" value in your programming environment, and then some garbage value in the grading machine environment. The result will be a program that by dumb luck runs "correctly" in your environment (but by accident!) and then, quite properly, fails in the other environment.

These days, many systems zero memory - both stack and allocated - as a security measure. But according to the C and C++ Standards, uninitialized memory is not required to have anything in particular in it - it often has garbage or it might have zeroes in it. Pre-zeroing memory isn't really helpful to the C/C++ programmer because it is NOT Standard and so can't be depended on. All it does is hide bugs because a zero value lying around in an unitialized pointer or string space can make defective code masquerade as valid code.

Important: Such a program is incorrect because it is relying on undefined behavior in the language. So this is a bug in your code, not a problem in the autograding system. You have to fix it to get credit. Hopefully you have allowed yourself time to track it down before the project deadline.

If you can pop your program into a different environment, you might be able to get the bug to show up. If not, then inspecting your code carefully by eye is often the fastest way to find the problem. Examine your program variables and your use of allocated memory and make sure they are all properly initialized - it is worthwhile to look especially for code that only works if zeros are present in the right places. This is one reason why constructors were invented - to help automate initializing complex collections of variables.

My computer or program crashes or hangs with a message about "illegal memory access", "access violation", "segmentation fault", "unmapped memory", "bus error", "memory could not be read", or "memory could not be written". Help!

Some of my variables and strings are changing value all by themselves! Am I going crazy?

My program crashes at a certain place, but I am positive that there is nothing wrong with that code - it doesn't even use any pointers or arrays!

My program works fine except when it reads "Barney Google" from the input file - this doesn't make any sense!

When my program crashes, it does something different every time! I thought computers were predictable!

These are all symptoms of misaddressing memory with overflowed arrays or wild pointers, a *very* common bug in C/C++ programming. Read more details about the above questions in: Array and Pointer Bugs.

OK, how did my program misaddress memory?

How can I find misaddressing bugs?