Learn something new every day
More Info... by email
An array of arrays in computer programming is a data structure that holds another array at each index. This means the datum at each sequential address in the topmost level array is actually the first datum element of each sub-array. In turn, each sub-array also can be an array of arrays, allowing the nesting of arrays as deeply as needed. Although the concept might seem complex, there actually are very simple declaration and dereferencing notations that allow an array of arrays to be very clearly expressed inside a program. One of the most common uses for an array of arrays is to store information in a grid pattern, as can be the case with an image.
An array is a series of data elements that, in most programming languages, is stored in consecutive memory locations. The datum held in an array is called an element, and each element occupies a position in the array known as an index. The start of an array is index zero, the next is index one, and so on. Instead of holding integers or characters, an array of arrays holds another complete array at each index. These sub-arrays at each index can themselves hold arrays, as well, providing the ability to create complex tree-like structures of data as needed.
One of the common uses for an array of arrays is to store information that can be indexed from a grid with column and row coordinates. This can be used to represent data on a spreadsheet, a two-dimensional (2D) image to be displayed on a screen, or even a chess board. Arrays of arrays that are three levels deep, meaning an array that holds arrays that hold a third level of arrays, can be used to represent information in a cube or can be used to represent a matrix of information in which each location has more than one attribute. In general, arrays of arrays that are deeper than three levels are not used, because the same functionality can be more simply implemented by using an array of structures or classes.
The programming notation for an array of arrays is much easier to decipher than might be expected. Most programming languages use brackets to denote the index of an array, and a multi-dimensional array is no different, except that an extra set of brackets is added to index the sub-array. For example, a single-dimensional array could be written as "array[ 2 ]" to denote the element at the second array index location. An array of arrays could be written in a similar way — array[ 2 ][ 1 ] — which indicates the datum element in the first index of the second array.
One of our editors will review your suggestion and make changes if warranted. Note that depending on the number of suggestions we receive, this can take anywhere from a few hours to a few days. Thank you for helping to improve wiseGEEK!