Header Ads Widget

Semantic Error

Semantic Error

During the semantic analysis phase, this type of error appears. These types of error are detected at compile time.

Most of the compile time errors are scope and declaration error. For example: undeclared or multiple declared identifiers. Type mismatched is another compile time error.

The semantic error can arises using the wrong variable or using wrong operator or doing operation in wrong order.

Some semantic error can be:

  • Incompatible types of operands
  • Undeclared variable
  • Not matching of actual argument with formal argument

Example 1: Use of a non-initialized variable:

  1. int i;  
  2. void f (int m)   
  3. {  
  4.       m=t;  
  5. }  

In this code, t is undeclared that's why it shows the semantic error.

Example 2: Type incompatibility:

  1. int a = "hello";      // the types String and int are not compatible  

Example 3: Errors in expressions:

  1. String s = "...";  
  2. int a = 5 - s;     // the - operator does not support arguments of type String  

Post a Comment

0 Comments