Multi dimensional Array in C++

Multi dimensional Array in C++ 

An array containing more than two dimensions is called multi-dimensional array. We can use more than two pairs of brackets to specify the size or refer any array element

Syntax :

<Type> Arr_name[s1][s2][s3]……………….;

Here, Type refers to any valid data type of C++. It can be any valid data type of C++ like int, float, char, structure, union, class etc.

Arr_name  specifies the name of array as defined by the programmer. The name of array must follow all the rules of a valid identifier of C++.

[ ] Square brackets are known as subscript, they are used to declare size of array within them.

s1,s2,s3,…. specify the dimensions in the multidimensional array. They should be integer values.

 

Program of  multi dimensional array in C++

#include<iostream> 
using namespace std;
int main()
 {
  int i,j,k;
  int arr3D[2][2][2]={3,4,5,6,8,9,7,1};
  cout<<"\nArray is=";
  for(i=0;i<2;i++)
  {
   for(j=0;j<2;j++)
   {
     for(k=0;k<2;k++)
     {
       cout<<endl<<arr3D[i][j][k];
     }
   }
 }
return 0;
}

 

Spread the love
Lesson tags: Multi dimensional Array in C++
Back to: C++ Programming Notes
Spread the love