We can work with Three Dimensional Array in C- Program.Basically Three Dimensional Arrays are array of an array.Like :
int table [10][10][10];
If we declare any array like above than compiler will allocate memory for 10*10*10 = 1000 array elements.
Basically more than one of two Dimensional Array makes Three Dimensional Array.Watch the program below :
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,k;
int table [3][4][2] = {
{1,2},
{3,4},
{5,6},
{7,8},
},
{
{9,10},
{11,12},
{13,14},
{15,16},
},
{
{17,18},
{19,20},
{21,22},
{23,24},
},
};
for(i=0;i<3;i++)
{
for(j=0,j<4,j++)
{
for(k=0;k<2;k++)
printf("\n array[%d][%d][%d]=",i,j,k);
} /*End for j*/
} /*End for i*/
getch();
}
Run This Program To See The OUTPUT.
Program Analysis :
-> In this program,Three for loop is used through i,j,k variable.
-> table [][][2]
here a one dimensional array is working including two array element.
-> table [][4][2]
Four One Dimensional Array generated a Two Dimensional Array here.
-> table [3][4][2]
Three Two Dimensional Array generated a Three Dimensional Array here.
Post a Comment