What Does "Out of Bounds" Mean on a Computer?

  • Print this article

One of the fundamental parts of any program is the variable. The variable represents a value stored into the computer's memory. The way in which programs access data is important, however: by using collections of data called arrays, it becomes possible for programmers to perform unintended computations using unknown values in memory. By going outside of the bounds of an array, a programmer essentially begins to possibly change values in memory that may represent important functionality for the program or for the entire system itself.

  1. Computer Memory

    • Memory in a computer system is arranged sequentially. This means that variables declared will reside in memory next to other variables, or other pieces of data. Memory slots are divided by their type, so that enough memory is set aside for each type. For example, if a program sets aside an integer variable and a character variable, it would designate two bytes of memory for the integer, then one byte for the character.


    • Programmers can also set aside arrays of values, which represent a collection of values under the same variable name. So instead of declaring five different integer variables that represent a list, the programmer declares an array of five values, which reside under the array name and are accessible by referencing the array's zero-based index. Accordingly, when a programmer sets aside an array, the computer sets aside enough continuous memory for the amount of values the array will hold. So, if the programmer declares an array of five integers, the computer will set aside the next available space in memory that can hold five integers.

    Arrays and Out of Bounds

    • The programmer can declare an array and access its values through accessing the indices that contain the values. However, in some programming languages, such as C, there is nothing to stop the programmer from accidentally attempting to access an index not part of the array. For example, a programmer using the five integer array might try to access a sixth value. The programmer has gone "outside the bounds" of the array: the value doesn't exist as part of the array, so now the programmer is trying to access memory outside of the array.

    Necessity of Bounds Checking

    • By going outside the bounds of the array, the programmer is now potentially manipulating data in other memory locations. Most likely, the programmer has no idea what is in this memory location: it could be data for another variable, or a reference location for another function. If a programming language does not check boundaries by disallowing programmers to access data outside of an array, the programmer could rewrite code that performs critical functions, of causes the current program to display unintended behavior.

Related Searches



Related Ads

View Mobile Site