Category: 

What Is an Array of Arrays?

Article Details
  • Written By: Eugene P.
  • Edited By: Angela B.
  • Last Modified Date: 25 August 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
Although Stonehenge is the most famous, there are over 1,000 ancient stone circles standing in the British Isles.   more...

September 26 ,  1960 :  The first televised US Presidential debate took place.  more...

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.

Ad

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.

Ad

You might also Like

Recommended

Discuss this Article

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email