top of page
Writer's pictureD A Rosi Arsida Wardani

Syntax and Logical Error

Updated: May 1, 2021

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 :

  1. There are no quotation marks (") after the word errors,

  2. There is no semicolon (;) on the 4th line,

  3. The program return with no value,

  4. 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.


Recent Posts

See All

One-dimensional Arrays

One-dimensional arrays are data structures that contain data types of the same type. In the form of a group of related memories...

Loop

Introduction Examples of algorithms in everyday life : Example 1 : To finish eating a plate of rice (initial conditions) Mouthfuls of a...

Comments


Post: Blog2_Post
bottom of page