Common Programming Errors in C Language

 




       The Programmer may come across errors while writing a computer program. In programming languages these errors are called "bugs", and the process of finding and removing these bugs is called debugging.
      When the C program compiler detects an error, it displays an error message describing the cause of the error. There are three types of programming errors, these are Syntax error, Runtime error, and Logical error.


1. Syntax Error


       A syntax error occurs when the program violates one or more grammar rules of C language. The compiler detects these errors as it attempts to translate the program into machine language. If a C statement has a syntax error then it cannot be translated by the compiler and the program cannot be executed, the compiler will stop translation and shows the error message.

Example


       Some examples of syntax errors are as follows:

  • A statement terminator is missing at the end of a C statement.
  • A misspelled function keyword is used in the program
  • Any of the delimiters is missing.

2. Runtime Errors


       A runtime error can occur when the program directs the computer to perform an illegal operation, such as dividing a number by zero. Runtime errors are detected and displayed by the computer during the execution of a program.

       When a runtime error occurs the computer stops executing and displays a diagnostic message.

Example

  • The user may ask the program to open a file that is not exist
  • The user may enter the wrong type of data

3. Logical Errors


       A Logical error occurs when a program follows a faulty algorithm. A program with the logical error may produce unexpected and wrong results. The compiler cannot detect logical errors, therefore no error message is reported from the compiler. 

       Moreover, these errors don't cause a program to be crashed and also they can't be recognized by the translator, that's why these are very difficult to detect. One can recognize logical error by looking through the program until one finds the error, instead of knowing the error and resolve it by going to the exact line of code that contains the error.

 Example

       Some example of logical error are as follows:

  • Using the wrong condition in a program such as writing <5 instead of >5.
  • Using a wrong formula in the program such as writing Average = Total * 5 instead of Average = Total/5.



Post a Comment

0 Comments