An Array is a group of elements with the same (homogeneous) data type. A 3D array is a multi-dimensional array. A multidimensional array is basically an array of arrays.
We can declare the 3-D array as:
int a[2][3][2];
The meaning of the above representation can be understood as:
- The memory allocated to variable a is of data type int.
- The total capacity that this array can hold is 2*3*2, which is equal to 12 elements.
- The data is being represented in the form of 2 arrays with 3 rows and 2 columns each.
In 3D arrays representation, the first square bracket represents the level of the array that has to be considered, second would be the number of rows, and the third one is for the number of columns.
The index representation of the array for the first element always starts with zero and ends with size-1. So, for example, if the number of rows is 3, then the index representation for accessing the data in rows will be 0, 1 and 2. The same logic applies for the array level and column indexes too. For the above representation, to get the data of 1st level of the array with 2nd row 2nd column, we can access by a[0][1][1].
Initializing 3D Arrays in C:
We can initialize a 3D array similar to the 2-D array.
int a[2][3][2]={ { { 0, 1 }, { 2, 3 }, { 4, 5 } }, { { 6, 7 }, { 8, 9 }, { 10, 11 } } };
Programming Example:
Example-1: Program to print elements of a three-dimensional (3D) array.
Output:
Example-2: program to read and print elements of a three-dimensional (3D) array.
Output:
Real Estate For the reason that the admin of this site is working, no uncertainty very quickly it will be renowned, due to its quality contents.
Real Estate Pretty! This has been a really wonderful post. Many thanks for providing these details.
Tech to Force Nice post. I learn something totally new and challenging on websites
you are in reality a just right webmaster The site loading velocity is incredible It seems that you are doing any unique trick In addition The contents are masterwork you have performed a wonderful task on this topic
Family Dollar For the reason that the admin of this site is working, no uncertainty very quickly it will be renowned, due to its quality contents.
Technoob Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
Blue Techker I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.
Thinker Pedia This is my first time pay a quick visit at here and i am really happy to read everthing at one place
Thinker Pedia This is my first time pay a quick visit at here and i am really happy to read everthing at one place
Newtoki You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!