answersLogoWhite

0

Syntax Error: error due to missing colon, semicolon, parenthesis, etc. Syntax is the way in which we construct sentences by following principles and rules.

Example: In C++, it would be a syntax error to say

int x = "five";

This will not compile because it does not follow the syntax of the language and does not make any sense to the compiler.

Semantic Error: it is a logical error. it is due to wrong logical statements. Semantics is the interpretations of and meanings derived from the sentence transmission and understanding of the message. Semantics errors are Logical, while Syntax errors are code errors.

Example: A semantic error would compile, but be incorrect logically:

const int pi = 12345;

Your program will likely compile and run without error but your results will be incorrect. (Note that these types of errors are usually much harder to debug)

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
RossRoss
Every question is just a happy little opportunity.
Chat with Ross
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
More answers

A semantic error is one related to the meaning of something. For example, a syntactically perfect statement made in the wrong context is a semantic error which may be detected at compile-time. On the other hand, misinterpreting a variable of a generic type (e.g. int) as a temperature value in Kelvin when it really holds units of Celsius is a semantic error which may not be detected at compile-time.

A logic error is one that refers to an incorrect program logic. For example, the following pseudocode snippet contains a logic error:

if (a > b) {

print("a is greater than b"); } else { print("a is less than b");}

(The error is that the second branch is true if a is less than or equal to b.)

Most compilers detect only few logic errors, but some sophisticated tools exist which can subject source code to very thorough examination, allowing the detection of such errors with a higher probability at compile-time. PC-Lint is an example for such a (commercial) tool.

User Avatar

Wiki User

12y ago
User Avatar

Semantics errors are Logical, Syntax errors are code errors.

User Avatar

Wiki User

15y ago
User Avatar

A syntax error is when the Asians rebooted the mother drive an made Koreans

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between semantic error and logical errors?
Write your answer...
Submit
Still have questions?
magnify glass
imp