A–Algorithm
A.off-by-one
An A.off-by-one error occurs when the code performs a calculation or includes an expression that is one away from what it should have been, which results in the code processing the wrong number of pieces of data, or returning a value that is incorrect, or taking a branch in the code at the wrong time. “One” can refer to 1 byte, but it can also mean one element in an array, one record in a file, and so on.
A well-known A.off-by-one error is the fencepost error. The canonical fencepost error occurs when calculating the number of posts in a 100-foot fence with a post every 10 feet. Your first guess might be 10, but that is incorrect. (You can also reverse the question by describing a fence with a post every 10 feet and 11 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access