During the syntax analysis phase, this type of error appears. Syntax error is found during the execution of the program.
Some syntax error can be:
When an invalid calculation enters into a calculator then a syntax error can also occurs. This can be caused by entering several decimal points in one number or by opening brackets without closing them.
For example 1: Using "=" when "==" is needed.
The following warning message will be displayed by many compilers:
Syntax Warning: assignment operator used in if expression line 16 of program firstprog.cpp
In this code, if expression used the equal sign which is actually an assignment operator not the relational operator which tests for equality.
Due to the assignment operator, number is set to 200 and the expression number=200 are always true because the expression's value is actually 200. For this example the correct code would be:
Example 2: Missing semicolon:
Example 3: Errors in expressions: