Multi-Dimensional Arrays (3D Arrays) in C Programming Language


C allows for arrays of two or more dimensions. A two-dimensional (2D) array is an array of arrays. A three-dimensional (3D) array is an array of arrays of arrays.

In C programming an array can have two, three, or even ten or more dimensions. The maximum dimensions a C program can have depends on which compiler is being used.

More dimensions in an array means more data be held, but also means greater difficulty in managing and understanding arrays.

How to Declare a Multidimensional Array in C

A multidimensional array is declared using the following syntax:

type array_name[d1][d2][d3][d4]………[dn];

Where each d is a dimension, and dn is the size of final dimension.


  1. int table[5][5][20];
  2. float arr[5][6][5][6][5];

In Example 1:

  • int designates the array type integer.
  • table is the name of our 3D array.
  • Our array can hold 500 integer-type elements. This number is reached by multiplying the value of each dimension. In this case: 5x5x20=500.

In Example 2:

  • Array arr is a five-dimensional array.
  • It can hold 4500 floating-point elements (5x6x5x6x5=4500).

Can you see the power of declaring an array over variables? When it comes to holding multiple values in C programming, we would need to declare several variables. But a single array can hold thousands of values.

Note: For the sake of simplicity, this tutorial discusses 3D arrays only. Once you grab the logic of how the 3D array works then you can handle 4D arrays and larger.

Explanation of a 3D Array

Let's take a closer look at a 3D array. A 3D array is essentially an array of arrays of arrays: it's an array or collection of 2D arrays, and a 2D array is an array of 1D array.

It may sound a bit confusing, but don't worry. As you practice working with multidimensional arrays, you start to grasp the logic.

The diagram below may help you understand:

3D Array Conceptual View
3D Array Conceptual View
3D array memory map.
3D array memory map.

Initializing a 3D Array in C

Like any other variable or array, a 3D array can be initialized at the time of compilation. By default, in C, an uninitialized 3D array contains “garbage” values, not valid for the intended use.

Let’s see a complete example on how to initialize a 3D array:



void main()
int i, j, k;
int arr[3][3][3]=   
			{11, 12, 13},
			{14, 15, 16},
			{17, 18, 19}
			{21, 22, 23},
			{24, 25, 26},
			{27, 28, 29}
			{31, 32, 33},
			{34, 35, 36},
			{37, 38, 39}
printf(":::3D Array Elements:::\n\n");


In the code above we have declared a multidimensional integer array named “arr” which can hold 3x3x3 (or 27) elements.

We have also initialized the multidimensional array with some integer values.

As I said earlier, a 3D array is an array of 2D arrays. I have divided elements accordingly for easy understanding. Looking at the C code sample above,

  • In lines 9-13, 14-18, and 19-23, each block is a 2D array.
  • Collectively, lines 2-24 make a 3D array.

To call values from the array, imagine the 3D array above as a collection of tables. Each nested bracket cluster is a table with rows and columns. To access or store any element in a 3D array you need to know its table number, row number, and column number.

An example: You need to access value 25 from the above 3D array. So, first check the table: in this case, 25 is in table 1 (remember: tables, rows, columns are counted starting at 0, so the second table is table 1). Once you find the table number now check which row of that table has the value and then check the column number. So applying above logic, 25 located in table 1, row 1, and column 1, hence the address is arr[1][1][1]. Print this address and you will get the output: 25.

The Conceptual Syntax of a 3D Array in C

The conceptual syntax for 3D array is this:

data_type array_name[table][row][column];

If you want to store values in any 3D array point first to table number, then row number, and lastly to column number.

Some hypothetical examples:

arr[0][1][2] = 32;
arr[1][0][1] = 49;

Storing Values in a Continuous Location Using a Loop

The pointer syntax above assigns values to a particular location of an array, but if you want to store values in multiple locations automataically then you should use a loop.

Here is an example using the for loop command:


void main()
int i, j, k, x=1;
int arr[3][3][3];
printf(":::3D Array Elements:::\n\n");

		arr[i][j][k] = x;

Your opinion

Is this tutorial helpful for you?

  • Yes, very much.
  • No, Not at all
  • I know this, but looking for more examples.
See results without voting

Comments 34 comments

Parvez 6 years ago

Thank you. Nicely explained.

chokies 5 years ago

thx for your clear explanation,

Suraj Verma 5 years ago

Thanks for the concept of 3D array

Ashish Kasampara 5 years ago

Nice example of the 3D arry but more example and easy to understand that type of example

santhosh 5 years ago

how to imlpementthat array

Vijay 5 years ago

how to store array of different data types?

rajkishor09 profile image

rajkishor09 5 years ago from Bangalore, Karnataka, INDIA Author

@Vijay : I think you can try array of structure, please check this link.

Rintu_achiever 5 years ago

thanx.I have solved my problem

ian 4 years ago

nice,thank you for explain.

drosanda 4 years ago

Are multidimensional arrays can be returned in a function? if can,i need an example, thx be4.

c language easy for concepts 4 years ago



thanks you sir c language understand help and concpet for easy understand.plz sir requst for c langague method

for easy understand.plz sir send my e-mail


i am mca student and the not undertstand the c and c is very important of IT student plz sir help send replay my email id.

thanks sir.

R.Nandhini 4 years ago

Thank u for the clear explanation.

Razi Ahmad 4 years ago

Thanks it's really nice........

santu das 4 years ago

in 3-D array 1st one is page 2nd is row and 3rd is it right??

rajkishor09 profile image

rajkishor09 4 years ago from Bangalore, Karnataka, INDIA Author

@Santu: that is right...

Ali 4 years ago


i need to write a code that emulates an LED display, and for the numbers ive set a 3D array. the problem i have is getting it to read from an input. ive tried storing the input in a char array and reading it using scanf() but it doesn't work. can you please tell me what i need to do


Janet 4 years ago

The example would be more useful if all of the dimensions were different [2][3][4] rather than [3][3][3].

Jamal 4 years ago

what is the purpose of multiple dimensional arrays if i can do the same with a one intentional array

like what ares the advantages and stuff like that

tharani 4 years ago

its vry useful to us vry nice................

alfred 3 years ago

write a program that reads in an array type int. you may assume that there are fewer than 50 entries in that array. your program determines how many entries are used. the output is to be a two column is a list of the district array elements; the second column is the count of the number of occurences of each element the list should be sorted on entries int first column largest to smallest

Chris Goodwin 3 years ago

has expanded my view

ivy biswas 3 years ago

i need to know the syntax for 3 D Array

ritesh patel 3 years ago

welll good, but i would like to know that how to perform subtraction of two array of 3d. for example a[0]-a1[1]. could u help me

natasha jane 3 years ago

hey........the codes and the explanation really helped I really cant understand the difference between the 3D array being demonstrated here

and a 2D array with multiple endls ???pls help me to figure out the difference


ritesh khanna 3 years ago

pls help

ganesh 2 years ago

in three dimentional array arr[3][3][3] means 3table 3rows and 3columns like that in four dimentional array arr[3][3][3][3] means?????

jp 8 months ago

arr[0][1][2] = 32;

arr[1][0][1] = 49;

how about in character or string?

how to initialize in 3d array?

balaganesh 8 months ago

i can't understand that 3D array. can u explain this

Parveen Anand 7 months ago

Great explain the 3D programmin g. Thanks alot.

Karan 6 months ago

Can you please explain how below array will be represented {Similar to pictorial representation shown above (Fig. 3D array memory map)}

I believe that in the 0th 2-D array there should be 3 rows (row0 , row1,row2)with 2 elements

But with some examples I've found it to be 2 rows with 3 elements in oth 2-D array and similar in 1st 2-d array

Below is the example

int main()


int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,3},{2,3},{3,4}}};


printf("%u %u %u %d\n",a,*a,**a,***a);

printf("%u %u %u %d\n",a+1,*a+1,**a+1,***a+1);


return 0;


priti 5 months ago

how to find the address of an item placed at particular location ?

Tarun 2 months ago

can u explain with the example of multi dimensional arrays???

Tarun 2 months ago

explain the multi dimensional array using 3d array multiplication

wycliff 7 weeks ago

so helpful. satisfied

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.

    Click to Rate This Article