 # Multidimensional Arrays

The C language allows arrays of any type including arrays of arrays. These are sometimes known as multidimensional arrays.

For Example:

``double x;``

is a declaration for an array, x, with 10   elements, each of which contains an array with   20 elements.

In the preceding example, each element of the array is accessed using the expression

``x[ i ][ j ]``

The Array indices can not be  folded into one subscript in c language,

`` x[ i , j ]``

## 2D or Two Dimensional Array

Visualizes a 2D array as a matrix that has both rows and columns

For example, an array declared as

``int a;``

the array elements are arranged as follows:

The general form of a 2D array declaration is:

``e_type a_name[r_size][c_size];``

where

• e_type is the type of the array elements
• a_name is the name of the array
• r_size is the number of rows in the array
• c_size is the number of columns in the array

The number of pairs of brackets, [ ], denotes the dimensionality.

## 2D Array Initialization

• An array initializer is a sequence of initializing values written as a brace-enclosed, comma-separated list.
• Each row is contained in braces.
• Each element in a two-dimensional array is referenced using an identifier followed by two subscripts [ ] [ ]
• The subscript values for both rows and columns begin with 0, and each subscript has its own set of brackets.
``int j = {{1,2},{3,4}};``

declares j to be a 2´2, 4-element, integer array whose elements have the initial values

``````j=1 j=2
j=3 j=4``````

The following three array initializations are equivalent.

``````int a = {1, 2, 3, 4, 5, 6};
int a = {{1, 2, 3}, {4, 5, 6}};
int a[ ] = {{1, 2, 3}, {4, 5, 6}};``````

## Higher Dimensional Arrays

C allows arrays to be defined with more than two subscripts. A three-dimensional (3D) array is really a series of two-dimensional arrays. For example, to declare a 3D array volume:

``int volume;``

Declares a 10´10´10 array containing 1000 elements: essentially 10 2D arrays, each containing 100 elements.

3D arrays are often used to specify 3D information.