💡⚡Beginner
Show Types of Errors
Different error types
Learn about different types of errors in C: Syntax, Runtime, and Logical errors.
Types of Errors
1. Syntax Errors (Compile-time)
Errors detected by the compiler due to incorrect syntax.
syntax_error_example.c
C
1// Missing semicolon2int x = 5 // Error: expected ';'34// Undeclared variable5y = 10; // Error: 'y' undeclared67// Mismatched brackets8if (x > 5) {9 printf("Greater");10// Error: missing closing brace2. Runtime Errors
Errors that occur during program execution.
runtime_error_example.c
C
1#include <stdio.h>23int main() {4 int a = 10, b = 0;5 6 // Division by zero - Runtime error7 int result = a / b; // Crash!8 9 // Array out of bounds10 int arr[5];11 arr[10] = 100; // Undefined behavior12 13 return 0;14}3. Logical Errors
Program runs but gives incorrect results.
logical_error_example.c
C
1#include <stdio.h>23int main() {4 int sum = 0;5 6 // Logical error: wrong loop condition7 for (int i = 1; i < 5; i++) { // Should be <= 58 sum += i;9 }10 11 printf("Sum of 1-5: %d\n", sum); // Prints 10, not 1512 13 return 0;14}Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials