Array of Arrays: what is it?

Print anything with Printful



An array of arrays is a data structure where each index contains another array. This allows for nesting of arrays and is commonly used for grid patterns. Programming notation uses parentheses to indicate the index of an array, with an extra set for sub-arrays. Arrays of arrays deeper than three levels are not recommended.

An array of arrays in computer programming is a data structure that contains another array at each index. This means that the data at each sequential address in the top-level array is actually the first data item in each sub-array. In turn, each subarray can also be an array of arrays, allowing arrays to be nested as deeply as necessary. Although the concept may seem complex, there are actually very simple declaration and dereference notations that allow an array of arrays to be clearly expressed within a program. One of the most common uses for an array of arrays is to store information in a grid pattern, such as an image.

An array is a series of data elements which, in most programming languages, are stored in consecutive memory locations. The data contained 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 containing integers or characters, an array of arrays contains another full array at each index. These sub-arrays in each index can also contain arrays, providing the ability to build complex tree data structures as needed.

One of the common uses of an array of arrays is to store information that can be indexed by a grid with column and row coordinates. This can be used to represent data on a spreadsheet, a two-dimensional (2D) image to display on a screen, or even a chessboard. Arrays of arrays three levels deep, that is, an array that contains arrays that contain a third level of arrays, can be used to represent information in a cube, or it can be used to represent an array of information where each position has more than one attribute. In general, arrays of arrays deeper than three levels are not used, as the same functionality can be implemented more simply using an array of structures or classes.

The programming notation for an array of arrays is much easier to decipher than one might expect. Most programming languages ​​use parentheses to indicate the index of an array, and a multidimensional array is no different, except that an extra set of parentheses is added to index the subarray. For example, a one-dimensional array could be written as “array( 2 )” to denote the element at the second index position of the array. An array of arrays could be written in a similar way — array( 2 )( 1 ) — indicating the datum element at the first index of the second array.




Protect your devices with Threat Protection by NordVPN


Skip to content