Home | Computer | Debugging in Turbo C++ | Different types of Error in C/ C++

Debugging in Turbo C++ | Different types of Error in C/ C++

August 13, 2022

An error in a computer program is known as a bug. The process of finding and removing bugs is known as debugging.

image of types of errors in c and c++

Types of Errors in C/C++

Different types of errors can occur in C++ programs.

Syntax error

There are different rules in a programming language, for writing a program is known as syntax. Programs are written according to the rules.

Syntax errors occur when an invalid statement is written in the program. The compiler detects syntax errors and displays an error message to describe the cause of the error. A program containing syntax errors can not be compiled successfully. There can be many causes of syntax errors.

An important cause of syntax error

  • The statement terminators are missing at the end of the statement.
  • A misspelled keyword.
  • Any of the delimiters is missing.

Example: Typing count instead of count is an example of a syntax error.

Logical Errors

A type of error that occurs due to poor logic of the programmer is called logical error. A statement with a logical error may produce unexpected and wrong results in the program. Logical errors are difficult to find because the translator cannot detect these errors. The logical errors can only be detected by examining the program thoroughly.

Different causes of logical errors

  • Using wrong conditions in the program such as writing a < 5 instead of a>5.
  • Using the wrong formula in the program such as writing Average = Total * 5 instead of Average = total / 5.

The logical error is the most difficult error because of some reasons:

  • It cannot be detected by the compiler.
  • It does not crash the program. That is why it is difficult to detect.
  • The user needs to review the whole program to find out a logical error.
  • It may take a lot of time for detecting logical errors.

Run – Time error

A type of error that occurs during the execution of the program is known as run–time error. It is caused when a statement directs the computer to execute an illegal operation such as dividing a number by zero.

The run-time error is detected and displayed by the computer during execution. Run-time errors are normally caused due to wrong input from the user. The computer stops executing the program and displays an error message if a runtime error occurs.

Example

The user may ask the program to open a file that does not exist. Similarly, the user may enter the wrong type of data etc.