Logic error

a bug in a program that causes it to operate incorrectly, but not to terminate abnormally

In Computer programming a logic error is a bug in a program, which causes it to work incorrectly. A logic error produces unintended behaviour or output. In many cases, the syntax of the program is correct. This means that the environment used to make the program will not show an error. This makes logic errors difficult to find.

Examples change

This example function in C to calculate the average of two numbers contains a logic error. It is missing brackets in the calculation, so it compiles and runs but does not give the right answer.

int average(int a, int b)
{
    return a + b / 2;     /* should be (a + b) / 2 */
}