Assignment#2
Name: Talal Ahmed
Reg No: FA24-BRG-062
Degree: BRG (2nd Semester)
Course: programming fundamentals t
Submitted to: Ahsan khawaja
Submission date: 10th April, 2025.
Question:
Differentiate by examples different types of programming errors in C.
Answer:
In C programming, there are several types of errors that a programmer may encounter. These errors
can be broadly classified into syntax errors, runtime errors, logical errors, and linker errors. Here are
the differences with examples:
1. Syntax Errors
These occur when the rules of the C language are violated. The compiler detects them during
compilation.
Example:
#include <stdio.h>
Example:
#include <stdio.h>
int main() {
int a = 10;
int b = 0;
int c = a / b; // Division by zero
printf("%d", c);
return 0;
Explanation: Division by zero causes a runtime error (may crash the program).
3. Logical Errors
These occur when the program compiles and runs, but the output is not as expected due to a
mistake in logic.
Example:
#include <stdio.h>
int main() {
int x = 5, y = 10;
int max = x < y; // Should be x > y
printf("Max: %d", max);
return 0;
}
Explanation: The programmer meant to find the maximum value, but used the wrong comparison
operator.
4. Linker Errors
These occur when the program is compiled but cannot be linked due to missing function definitions
or libraries.
Example:
#include <stdio.h>
void display(); // Function declared
int main() {
display(); // Called but not defined
return 0;
Explanation: The function display() is declared and called but not defined anywhere in the program.