Three Dimensional Array

  • Three Dimensional array is the combination of 2 Dimensional array.
  • Let us take an example like there is a book, and inside the book, we see several different topics on the index page. We can say that a book is a 3 Dimension array, and the topics inside the book on the index page is a 2 dimension array.

  • Three-dimension Array is represented as :
    Three-dimensional-array-c

  • below table is the diagrammatical representation of the three-dimension Array

Three-dimensional-array-c

Let us perform some operations

 on three-dimension Array


  1.     printf(“%d “,table[0][1][1]);

Output::  4  // observe the table for understanding the output

·       2.  printf(“% u”, table);

Output :: 1000  // base address of the table

·       3.   printf(“%u “, table[2][1]);

Output::  1028 // address of the third 2D array, first row.

·      4. printf(“%u “, &table[1][2][1]);

  Output:: 12

·      5. printf(“%u “,table[1]);

Output :: 1012

Demo Program

#include<stdio.h>
int main()
{
 int table[3][3][2],i,j,k;
 
  printf(" Three Dimension Array\n");
 for(i=0;i<3;i++)
 {
  for(j=0;j<3;j++)
  {
   for(k=0;k<2;k++)
   {
    printf("enter at table[%d][%d][%d]=",i,j,k);
    scanf("%d",&table[i][j][k]);
   }
  }
 }
  for(i=0;i<3;i++)
 {
  printf("\n\t\n");
  for(j=0;j<3;j++)
  {      
    printf("\n");
   for(k=0;k<2;k++)
   {
    printf("%d ",table[i][j][k]);
   }
  }
 }
 return 0;
 }

output::

Three-dimensional-array-c



Refer also::