Errors in a C program

Error is a condition either during compilation or execution of a program which if not fixed can halt compilation or execution. There are three types of errors — syntax, logical, and run-time errors.

Syntax Error

These errors occur because of wrongly typed statements, which are not according to the syntax or grammatical rules of the language. For example, in C, if you don’t place a semi-colon after the statement it results in a syntax error.

Screenshot from 2020-07-11 20-27-07

These errors are caught by compiler during compilation and can be fixed by correcting the syntax of the statement.

Logical Error
These errors occur because of logically incorrect instructions in the program. Let us assume that in a program which was supposed to do addition of 2 numbers, it was wrongly written to perform subtraction. This logically incorrect instruction will produce wrong results. Detecting such errors is difficult as they only surface during run-time that too occasionally.

Runtime Error

These errors occur during the execution of the programs though the program is free from syntax and logical errors. Some of the most common reasons for these errors are
1. When you instruct your computer to divide a number by zero.
2. When you instruct your computer to find logarithm of a negative number.
3. When you instruct your computer to find the square root of a negative integer.