Multi-dimensional array is an array of array or more precisely collection of array. Unlike one-dimensional array, multi-dimensional array stores collection of array.
Let us revise the concept of dimension.
- One-dimensional array : Collection of data/values.
- Two-dimensional array : Collection of one-dimensional array.
- Three-dimensional array : Collection of two-dimensional array.
- N-dimensional array : Collection of
N-1
dimensional array.
We can declare array with any dimension. However, two-dimensional array is most popular and widely used to solve many mathematical problems.
Note: Whether it is one, two or N-dimensional array. All array elements are stored sequentially in memory.
Two-dimensional array
Two-dimensional array is a collection of one-dimensional array. Two-dimensional array has special significance than other array types. You can logically represent a two-dimensional array as a matrix. Any matrix problem can be converted easily to a two-dimensional array.

Syntax to declare two-dimensional array
type
is a valid C data type.array_name
is a valid C identifier that denotes name of the array.row-size
is a constant that specifies matrix row size.col-size
is also a constant that specifies column size.col-size
is optional when initializing array during its declaration.
Example to declare two-dimensional array
The above statement declares a two-dimensional integer array of size 3×4 i.e. 3 rows and 4 columns (in terms of matrix).
How to initialize two-dimensional array
You can initialize a two-dimensional array in any of the given form.
If you have mentioned row and column size specifically then curly braces for each row inside array initialization is optional. Hence, you can write the above initialization as.
Note: Be cautious while using the above approach to initialize. You must explicitly provide row and column size. Otherwise C compiler will generate compilation errors.
Array column size is optional if specifying individual rows within pair of curly braces.
There are several ways to initialize a two-dimensional array. It depends on programmers how they initialize. However, the first approach is considered as standard to initialize a two-dimensional array.
How to access two-dimensional array
Two-dimensional array uses two index values to access a particular element. Where first index specifies row and second specifies column to access.
Example to access two-dimensional array
Since array indexes are integer value, hence you can also wire a loop to access two-dimensional array. Two-dimensional array needs two index values to access any array element. Therefore you need two loops. One outer loop to access for each row of the matrix, second loop for each column of the matrix.
Example program to use two-dimensional array
Write a C program to declare a two-dimensional array of size 4×3. Read values in each element of array from user and display values of all elements.
Output –
Example program to use three-dimensional array
Output –
Recommended matrix example programs
- Program to add two matrix.
- Program to subtract two matrix.
- Program to check matrix equality.
- Program to multiply two matrices.
- Program to find transpose of a matrix.
- Program to check identity matrix.
Practice more matrix programming exercises to learn more.