Some of the errors refuse the program from getting compiled or executed.Those errors are always detected either during the time of compilation or execution.Thus errors are removed before compiling and executing.
There are mainly five types error are detected in C programming language:
Syntax error: Syntax error are also known as compilation error and then they are only comes at the compile time.
Compiler error indicates something because that they must be fixed before the code can be compiled. Most conman syntax error are:
Missing Parenthesis (})
Printing the value of without declaring it
int x = 15;
int y = 12;
printf("%d" ,(x,v)) //semicolon missed
error: expected ';' before '}' token
Run-time error: Errors exist during the execution time after successful compilation are called run-time errors.Program is running and we are not able to perform the operation is the main cause of the run-time errors.The most common run-time error is division by zero are also known as division error.
You can understand these examples better after seeing
printf("result = %d",n);
warning: division by zero [-Wdiv-by-zero]
n = m/0;
Linker error: Linker errors are mainly shown when the executable file of the program is not created.Thus error occurs when after compilation we link the different object file with main’s object.This are wrong functions prototyping, incorrect header files.The most common linker error is Main() instead of main().
Let’s understand through a simple example
printf("The value of a is : %d", a);
(.text+0x20): undefined reference to `main'
Logical error: In those logical errors compilation and execution of a program desired output is not obtained when certain input values are given.
These are one of the most common errors done by beginners of programming.These errors are mainly depends upon the logical thinking of the developer.
Let’s understand through an example:
for(int i=1;i<=10;i++); // logical error, as we put the semicolon after loop
printf("The value of sum is %d", sum);
The value of sum is 1
In the above code we are trying to print the sum of 10 digit , but we got the wrong output as we put the semicolon (;)
after the for loop, so the inner statements of the for loop will not execute. This produces the wrong output.
Semantic error: Thus error occurs when the statements are not understandable by the compiler.
Let’s understand through the example
a+b=c; // semantic error
error: lvalue required as left operand of assignment
a + b = c; //semantic error