Types of errors in C Language

1. Syntax Errors:

Occurs when there is error in sourcecode(when the syntax of the language is not respected).

Example: Missing Semicolon

int a=5 //semicolon is missing

Example: Errors in expression

x=(3+5; //Missing closing parenthesis’)’

y=3+*5; //Missing argument between ‘+’ and ‘*’

2. Semantic Errors: Indicates improper use of statements

Example: Use of non-initialized variable

int i;

i++; //The variable i is not initialized

Example: Type incompatibility

int a=”hello”; // the datatype int and string are not compatible

Example: Errors in expression

string a=”hello”;

int b=5-s; // the operator – does not support arguments of type string

Example 4: Unknown references

  • strin x; //strin is not defined
  • String s; s.println(); //Println is not method of class String

3. Logical Errors: Occurs in the output of the program. The program is compiled and executed without errors but generating unexpected output comes under logical errors.

Example :

int i=1;

while(i<=1) //Infinite loop does not terminate


4. Run Time Errors: Occurs when the program is running.

Example: Divide by Zero

int a=10,b;

b=a/0; //infinite


FileReader f=new FileReader(“file.txt”); // Error occurs only when the file “file.txt” not exists on the harddisk.

Leave a Reply

(*) Required, Your email will not be published