Syntax errors occur when the program code violates the syntax i.e. the grammar rules of the language. A missing ";" in the end of a statement is an example of a syntax error in C++. A compiler finds all the syntax errors.
When an error has been located an error message is printed and the line number where the error is located is given. The error message usually starts with "syntax error" or "parse error".
Semantical errors
Semantical errors occur when the code is syntactically correct but the compiler can't understand it anyway. A good example of semantical error is if "endl" is misspelled "ndl". These kinds of errors are always found by the compiler.
In case of semantical error an error message is also printed. A semantical error usually confuses the compiler and then there is an abundance of error messages. It is recommended always to correct the errors in the order the compiler gives them.
No comments:
Post a Comment