Type of Programming Errors in C

Type of Programming Errors in C

Syntax errors

A syntax error occurs when the code given does not follow the syntax rules of the programming language. Examples include:

  • misspelling a statement, eg writing pint instead of print
  • using a variable before it has been declared
  • missing brackets, eg opening a bracket, but not closing it

A program cannot run if it has syntax errors. Any such errors must be fixed first. A good integrated development environment (IDE) usually points out any syntax errors to the programmer.

Logic errors

A logic error is an error in the way a program works. The program can run but does not do what it is expected to do.

Logic errors can be caused by the programmer:

  • incorrectly using logical operators, eg expecting a program to stop when the value of a variable reaches 5, but using <5 instead of <=5
  • incorrectly using Boolean operators
  • unintentionally creating a situation where an infinite loop may