CPP Multidimensional Arrays

A multidimensional array is an array containing two, three, four, five, or more arrays. The increasing number of dimensions, increases the code complexity for the developers. The most popular arrays are single, two and three dimensional arrays.

Two dimensional Arrays:

A two-dimensional array can be defined as an array of arrays that needs two indices for every element.

Three dimensional Arrays:

A three-dimensional array can be defined as an array of arrays of arrays that needs three indices for every element.

Example: Accessing the elements of a two dimensional array.

#include <iostream.h>
using namespace std;
 
int main()
{  
int a[2][2] =  
	{  {2, 5}, {4, 0}  };
int b[2][2] =  
	{  {4, 5},  {4, 8}  };
int c[2][2] =  
	{  {0, 0},  {0, 0}  };
int i,j;    
 
for(i=0;i<2;i++)    
{    
for(j=0;j<2;j++)    
{    
c[i][j] = 0;
c[i][j] = a[i][j] + b[i][j];
cout << c[i][j]<<endl;
}   
}
return 0;
}

Output

6                              
10                          
8        
8
Please Share