C_Programming_Errors_Theory
C_Programming_Errors_Theory
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.
1. Syntax Errors:
These occur when the programmer breaks the rules of the C language grammar. Detected during
compilation.
Example:
int main() {
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;
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
4. Linker Errors:
Occur when the program is compiled but the linker fails to resolve function names or variables.
Example:
int main() {
fun(); // Called
5. Semantic Errors:
These occur when the syntax is correct, but the meaning of the program is not logically valid.
Example:
Summary Table:
------------------|-------------------|-------------------------------|------------------|--------------|-----------------
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
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.