Question: What are the different types of errors in C? Explain with examples.
Answer
Errors are the problems or the faults that occur in the program. There are commonly five types of errors exist in C programming:
- Syntax error
- Run-time error
- Linker error
- Logical error
- Semantic error
Syntax error
Syntax errors are also known as the compilation errors as they occurred at the compilation time. These errors are mainly occurred due to the mistakes while typing when programmer does not follow the grammar rule of the programming language. These errors can be easily corrected.
Commonly occurred syntax errors are: using variable without its declaration, missing the semicolon (;) at the end of the statement.
Run-time error / Execution Error
The errors exist during the execution-time even after the successful compilation known as run-time errors. When the program is running, and it is not able to perform the operation is the main cause of the run-time error. The division by zero is the common example of the run-time error. These errors are very difficult to find, as the compiler does not point out to these errors.
Linker error
Linker errors are mainly generated when the executable file of the program is not created. This can be happened either due to the wrong function prototyping or usage of the wrong header file.
Logical error
The logical error is an error that leads to an undesired output. These errors produce the incorrect output, but they are error-free, known as logical errors. The occurrence of these errors mainly depends upon the logical thinking of the developer.
Semantic error
Semantic errors are the errors that occurred when the statements are not understandable by the compiler. The following can be the cases for the semantic error:
No comments:
Post a Comment