Wednesday, January 4, 2012

What is debugging?

In your source code, looking for and correcting errors or mistakes that cause your programs to behave unexpectedly is called debugging. In general, there are three types of errors in a C source code: syntax errors, run-time errors, and logic errors.

Syntax errors are mistakes cause by violating the "grammar" rules of C. They easily can be caused by typographical mistakes or a lack of knowledge of the forms of statements required by C. These errors often can be diagnosed by the C compiler as it compiles the program. If your computer indicates errors when your try to compile a program, it will not translate your code into machine instructions. You must fix the errors before the compiler will translate your code. Therefore, when you have syntax errors you will not generate any output, even if your syntax errors are very minor and located in the very last lines of code.

Run-time errors, also called semantic errors or smart errors, are caused by violation of the rules during execution of your program. The compiler does not recognize them during compilation. However, the computer displays a message during execution that something has gone wrong and (usually) that execution is terminated. If a run-time error occurs near the end execution, you may get some of your results. The error message given by the computer may help you locate the source of error in your code.

Logic errors are the most difficult errors to recognize and correct, because the computer does not indicate that there are errors in your program as it does with syntax and run-time errors. It is up to you to identify that there is a problem at all. It is up to you to look at your output and decide that it is incorrect. In other words, your program may have appeared to have executed successfully, perhaps giving very reasonable results. However, the answer maybe completely wrong. You must recognize that they are wrong and correct code in the program. (Be careful though. Many hours have been spent looking for bugs in programs only to find out that the program is correct, but the input data is incorrect.)

No comments:

Post a Comment