## Types of Array

There are two types of array categories in C language –

— One-dimensional Array

— Multi-dimensional Array

#### One- dimensional Array

One dimensional array is also known as a linear array. it has only one row with multiple columns.

###### Syntax

dataType array_variable_name[MAXIMUM_COLUMN_COUNT];

###### Example

Above array is a one-dimensional array because it has only one row but 5 columns. I have already mentioned the one-dimensional array in Array Introduction.

#### Multi-Dimensional Array

However, C allows many dimensional arrays like 2-D,3-D,4-D……n-D as per the compiler support but here I am explaining only 2 types of Multi-dimensional array.

— Two-Dimensional Array

— Three-Dimensional Array

##### Two- dimensional Array

A two-dimensional array is an array of one-dimensional array.

Two-dimensional array expands along both direction (x and y) i.e it has multiple row and columns.

###### Syntax

dataType array_variable_name[ROW_COUNT][COLUMN_COUNT];

OR

dataType array_variable_name[ ][COLUMN_COUNT];

In the second Syntax if we know the column count in one row then we can calculate row count but vice-versa is not possible.

like if COLUMN_COUNT=5 and  total element Count=20 then

ROW_COUNT= COLUMN_COUNT / 5 =4

###### 2-D Matrix/Array representation

For E.g We can access element of 1st row and 0th column like this –

###### 2-D Matrix-Program

Write a program to display n x m matrix where n is the row and m is the column of the matrix.  a user will enter the desired number of row and column at runtime.

Suppose user enters n=2 and m=3 then matrix must represent like this – where Matrix[n][m]= any user input

Output:

##### Three-dimensional Array

A three-dimensional array is an array of two-dimensional array.

A three-dimensional array has 2-dimensional blocks in all 3 directions(x, y, z).

Syntax

dataType array_variable_name[2D_Block_Count][ROW_COUNT][COLUMN_COUNT];

2D_Block_Count: Total number of 2D array Count

ROW_COUNT: Row count in each block of 2D array

COLUMN_COUNT: Column Count in each block of 2D array

###### Syntax–Example

In above example-

2D_Block_Count: 2

ROW_COUNT: 2

COLUMN_COUNT : 3

In above example, you can see that there are two sets of the two-dimensional array.

###### Pictorial representation of 3-D array memory Map

We can access elements at any index of 3-D array like this –

###### 3-D Matrix Program

Write a program to display b x n x m 3-D matrix where b is the 2-d block count, n is the row and m is the column of each 2-d matrix.  a user will enter the desired number of blocks, row, and column at runtime.

Output:

So here I have tried to cover all of the basics of the one-dimensional and multi-dimensional array and I will discuss the use of pointers and function in the array in upcoming chapters .you must see the example section to get your concepts more clear.

### Subscribe and stay updated with our latest articles.

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Embedclogic will use the information you provide on this form to be in touch with you and to provide updates and marketing.