Syntax Error
Syntax errors are errors in the source code which are related to the syntax of the language. Syntax errors are detected by the compiler and reported in the form of error messages. It can cause the compilation process to not be generated.
For example :
#include <iostream>
using namespace std;
int main (){
cout<<"This program has errors
return;
In the above program, there are some syntax errors. The compiler will automatically detect it, and showing an error message like this :
It can be seen, that some of the errors are :
There are no quotation marks (") after the word errors,
There is no semicolon (;) on the 4th line,
The program return with no value,
And, expected '}' at the end of input.
To run the program successfully, we have to fix that errors. The program should look like this :
#include <iostream>
using namespace std;
int main (){
cout<<"This program has errors";
return 0;
}
Output :
Logical Error
A logical error is an error that is related to program logic. For example, if we run the program successfully, but the result is not what kind of result we want.
It may not be detected by the compiler, but we can detect it when we see its output.
Comments