Logical Error

Definition – What is Logical Error

The Logical Error is a program error made by the programmer while writing the program source code. In general, logical error executes unexpected results for logic value. Both interpreter and compiler and even scripting language has logical errors. Unlike syntax error and runtime error, the logical error cannot be detected by the compiler and interpreter.

Basically, logical errors occur while writing the variable logic, for example, calculating something. A logical error does not give any error popup with an error code but it does not execute the desired output as intended. Let’s see some logical error examples made by the computer programmer.

Examples of Logical Error

Here an example in C programming making a logical error:

#include <stdio.h>
int a, b, average;
int main() {
   average = a + b / 2; //here shoud be (a + b) / 2
   printf (average"\n");
   return 0;
 }

In the above code, writing a + b / 2 will make a logical error. Because this can not calculate the average value of a and b correctly. Because if we run the program then at first b will be divided by 2 then the calculated value will be added with a. that really does not make sense to get the average.