CodesJava

Easy learning with example program codes

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
Posted in CPP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki