![]() |
VOOZH | about |
Program 1:
Below is the code to demonstrate the semantic error:
Explanation:
Program 2:
Below is the correct code i.e, without any syntax and semantic errors.
GFG!
| Basis | Syntax | Semantics |
|---|---|---|
| Meaning | It refers to the rules of any statement in the programming language. | It refers to the meaning associated with any statement in the programming language |
| Error | It is referred to as a syntax error. It is generally encountered at the compile time. It occurs when a statement that is not valid according to the grammar of the programming language. Some examples are missing semicolons in C++, using undeclared variables in Java, etc. | It referred to as a semantic error. It is generally encountered at run time. It occurs when a statement is syntactically valid but does not do what the programmer intended. This type of error is tough to catch. |
| In linguistics | The syntax is the arrangement or order of words, determined by both the writer’s style and grammar rules. | There are two areas of semantics that are logical semantics and lexical semantics. |
| Sensitivity | The syntax is case sensitive in most programming languages. | Most of the semantics are case-insensitive. |