Off-by-one error is an exceedingly common programming error.

For example, array access can easilly be off-by-one in languages whose compilers do not check array boundaries before compiling. An example of an off-by-one error causing out of bounds array access is shown in the following code:

dataArray[80];

for ( i=0; i <= 80; i++ )
        dataArray[i] = 0;

Because the array begins at 0 and not 1 (making the last array element 79, not 80), the for loop will cause the array to overflow. It is easy to see why this error is so common.

OffByOneError (last edited 2008-07-09 05:47:53 by localhost)