Errors in C Programming
Errors in C Programming
Syntax Errors:
These are errors that occur when the code does not follow the grammatical rules of
the programming language.
Examples:
Missing parentheses or brackets.
Using an incorrect keyword (e.g., "prin" instead of "print").
Incorrectly formatted code (e.g., missing semicolons).
Semantic Errors:
These errors occur when the code is syntactically correct but does not make sense in
the context of the language's rules or the programmer's intended logic.
Examples:
Using an undeclared variable.
Trying to perform an operation on incompatible data types.
Calling a function with the wrong number or type of arguments.
Example: An algorithm that incorrectly calculates a result, a loop that runs forever, or a
program that doesn't handle certain inputs correctly.
Run-time Errors
A runtime error happens during the execution of a program, meaning the code has been
compiled or interpreted and is running, but something goes wrong.
Causes:
Resource issues: The program might run out of memory, disk space, or other system
resources.
Unexpected input: The program might receive data or instructions it wasn't designed to
handle.
Logic errors: The program's logic might lead to an error, such as dividing by zero or
accessing an invalid memory location.
External factors: Problems with hardware, network, or other software can also cause
runtime errors.
Examples:
Division by zero: Attempting to divide a number by zero.
Array out of bounds: Trying to access an element of an array that doesn't exist.
Null pointer exception: Trying to access a variable that hasn't been assigned a value.
File not found: Trying to open a file that doesn't exist.
How to handle them: