Logical Errors
Even if the syntax and other factors are correct, we may not get the desired results due to logical issues. These are referred to as logical errors. We sometimes put a semicolon after a loop, which is syntactically correct but results in one blank loop. In that case, it will display the desired output.
Example: In the below example, the for loop iterates 5 times but the output will be displayed only one time due to the semicolon at the end of for loop. These kinds of errors are called logical errors.
C++
// C++ program to demonstrate // a logical error #include <iostream> using namespace std; int main() { int j; // Cause of Logical error for (j=0;j<=5;j++); { cout << "Geeks for geeks" ; } return 0; } |
Geeks for geeks
C++ Program to Show Types of Errors
In any programming language errors is common. If we miss any syntax like parenthesis or semicolon then we get syntax errors. Apart from this we also get run time errors during the execution of code. In a similar way the errors are classified as below:
- Syntax Errors
- Runtime Errors
- Logical Errors
- Linked Errors
- Semantic Errors