C Programming: Complete Theory Revision Booklet
Types of Errors in C Programming
What is an Error in Programming?
An error is any mistake in the program that prevents it from running correctly or compiling successfully. Errors
can occur due to incorrect syntax, wrong logic, improper input, or unexpected conditions.
Main Types of Errors in C:
1. Syntax Errors:
These occur when the programmer breaks the rules of the C language grammar. Detected during
compilation.
Example:
int main() {
printf("Hello World"); // Missing semicolon - Syntax error
return 0;
2. Logical Errors:
These occur when the program runs without crashing, but gives wrong output due to a mistake in logic. Not
detected by compiler.
Example:
int a = 5, b = 10;
printf("Sum = %d", a - b); // Logical error: should be a + b
3. Runtime Errors:
These happen while the program is running, often due to illegal operations (like division by zero). Detected
during execution.
Example:
int a = 10, b = 0;
C Programming: Complete Theory Revision Booklet
printf("%d", a / b); // Runtime Error: Division by zero
4. Linker Errors:
Occur when the program is compiled but the linker fails to resolve function names or variables.
Example:
void fun(); // Declared
int main() {
fun(); // Called
// No definition for fun() - Linker Error
5. Semantic Errors:
These occur when the syntax is correct, but the meaning of the program is not logically valid.
Example:
float area = 3.14 * 5 * 5; // Should use 3.14f for float accuracy
Summary Table:
Type of Error | When Detected | Causes | Detected By | Can Compile? | Output?
------------------|-------------------|-------------------------------|------------------|--------------|-----------------
Syntax Error | Compile-time | Wrong grammar/syntax | Compiler | No | No
Logical Error | Run-time or later | Wrong logic | Programmer | Yes | Wrong output
Runtime Error | Run-time | Invalid operations (e.g. /0) | System at run | Yes | May crash
Linker Error | Linking stage | Missing definitions | Linker | No | No
Semantic Error | Compile-time | Misuse of correct syntax | Compiler/Logic | Yes or No |
Unexpected
Conclusion:
Understanding different types of errors is essential for writing correct and efficient C programs. Syntax errors
are easiest to fix, but logical and runtime errors require careful thinking, testing, and debugging.