Types of Errors In C Programming Language
- Syntax error
- Run-time error
- Linker error
- Logical error
- Semantic error
Let's discuss them one by one.
Syntax error
Syntax errors are those errors which occur when we violate the rules of writing C syntax. These are also called compile-time error. This error tells whats need to be corrected in the program. These error are detected by compiler.
Most common syntax errors are missing semicolon, pranthesis, etc.
Code
#include<stdio.h>
int main(){ printf("Crackexams99.com") return 0;}
Output
c.c: In function 'main':c.c:4:31: error: expected ';' before 'return' printf("Crackexams99.com") ^ ; return 0; ~~~~~~
Run-time error
These are errors which occurs during the execution-time even after the successful compilation of the program. The division by zero is one of the common example for run-time error.
Code
#include <stdio.h> int main() { int a=2/0; printf("%d", a); return 0; }
Output
c.c: In function 'main':c.c:4:12: warning: division by zero [-Wdiv-by-zero] int a=2/0; ^
Linker error
These are errors which occurs due to wrong function prototyping, incorrect header files. For example typing print instead of printf or Main instead of main.
Code
#include <stdio.h> int Main() { int a=2; printf("%d", a); return 0; }
Output
Return error
Logical error
On Compilation desired output is not obtained. These are error free for compiler.
Code
#include <stdio.h> int main() { int a=8/3; printf("%d", a); return 0; }
Output
2
Semantic error
These are errors which occur when the statements are not meaningful for the compiler. Like uninitialized variables, using unsuitable data types.
Code
#include <stdio.h> int main() { int a; a = a + 1 ; printf("%d", a); return 0; }
Output
Return Garbage Value