What is a multidimensional array? Explain with program

CServer Side ProgrammingProgramming

C language allows arrays of three (or) more dimensions. This is a multidimensional array. The exact limit is determined by compiler.

Syntax

The syntax is as follows −

datatype arrayname [size1] [size2] ----- [sizen];

For example, for three – dimensional array −

int a[3] [3] [3];

Number of elements = 3*3*3 = 27 elements

Example

Following is the C program for multidimensional array −

 Live Demo

#include<stdio.h>
main ( ){
   int a[2][2] [2] = {1,2,3,4,5,6,7,8};
   int i,j,k;
   printf ("elements of the array are :\n");
   for ( i=0; i<2; i++){
      for (j=0;j<2; j++){
         for (k=0;k<2; k++){
            printf("%d", a[i] [j] [k]);
         }
      }
   }
}

Output

When the above program is executed, it produces the following result −

Elements of the array are :
1 2 3 4 5 6 7 8
raja
Published on 09-Mar-2021 12:04:00
Advertisements