Syntax Error

Definition – What is Syntax Error

Every programming language has its own basic syntax. Basic syntax consists of some notation and signs to construct programming instruction. While writing source code missing any basic syntax make a program error called syntax error. Both compiled and interpreted language has syntax errors and syntax error can be detected by compiler and interpreter. A single line of syntax error code prevents to compile and execute a program.

Unlike runtime error and logical error, syntax error can be detected while compiling. With a single syntax error, a program even cannot be compiled. It is one kind of grammatical errors. Scripting languages like PHP, Python also have syntax errors. Using some advanced source code editor the syntax error can be detected in real-time. Modern IDE’s like CodeBlock or Netbeans can detect the syntax error and indicate the error with a red warning at the errored line number.

Examples of Syntax Error

In the C programming language, the following syntax error may occur while writing or editing the source file.

#include <stdio.h>
int main() {
    printf("Hello, World!")   //here missing the semi-colon (;)
                              //makes syntax error
}

In the above source code, there is a syntax error in line. Because in C programming language using the semi-colon after every statement is the must. And it is a basic syntax of C programming. Avoiding semi-colon after a single line of statement won’t compile the program.