Types of Errors
Types of Errors
1. Syntax Error
3. Logical Error
4. Semantic Error
5. Linker Error
Syntax Error
Syntax errors occur when a programmer does not follow the set of rules
defined for the syntax of C language.
Syntax errors are sometimes also called compilation errors because they
are always detected by the compiler.
Runtime Error
Errors that occur during the execution (or running) of a program are
called RunTime Errors.
These errors occur after the program has been compiled successfully.
When a program is running, and it is not able to perform any particular
operation, then error will be generated that is called a RunTime error.
For example, while a certain program is running, if it encounters the
square root of -1 in the code, the program will not be able to generate an
output because calculating the square root of -1 is not possible. Hence,
the program will produce an error.
Runtime errors can occur because of various reasons. Some of the reasons
are:
1. Mistakes in the Code: Let us say during the execution of a while loop,
the programmer forgets to enter a break statement. This will lead the
program to run infinite times, hence resulting in a run time error.
Logical Error
Semantic Error
Errors that occur because the compiler is unable to understand the written
code are called Semantic Errors.
A semantic error will be generated if the code makes no sense to the
compiler, even though it is syntactically correct. It is like using the wrong
word in the wrong place in the English language.
For example, adding a string to an integer will generate a semantic error.
Semantic errors are different from syntax errors, as syntax errors signify
that the structure of a program is incorrect without considering its
meaning. On the other hand, semantic errors signify the incorrect
implementation of a program by considering the meaning of the program.
The most commonly occurring semantic errors are: use of un-initialized
variables, type compatibility, and array index out of bounds.
Linker Error
Linker is a program that takes the object files generated by the compiler
and combines them into a single executable file.
Linker errors are the errors encountered when the executable file of the
code cannot be generated even though the code gets compiled
successfully. This error is generated when a different object file is unable
to link with the main object file.
We can run into a linked error if we have imported an incorrect header
file in the code, we have a wrong function declaration, etc.