Jump to content

Logic error

From Simple English Wikipedia, the free encyclopedia
Revision as of 22:22, 23 August 2015 by Eurodyne (talk | changes) (Disambiguate Bug to Software bug using popups)

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 corrrect. This means that the environment used to make the program will not show an error. This makes logic errors difficult to find.

Examples

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 */
}