Posted By:
2 Jul, 2013 6:45 am PDT

Multi-dimensional arrays in C++

What are multi-dimensional arrays? How to implement them and how to access elements in an array?
Attachment:None


Multi-dimensional arrays can be described as “arrays of arrays”. For example, a bi-dimensional array can be imagined as a bidimensional table with all elements with same data type.

int a[3][5] is a bi-dimensional array.

Here, no of rows=3 and no of columns=5.

Multi-dimensional arrays are just an abstraction for programmers, since we can obtain the same result with the help of a single-dimensional array.

Eg:

int a[3][5]   //is equivalent to

int a[15]      // (3*5)=15

 

 The code snippet for accessing multi-dimensional array is:

int a[3][5];

int m;             //no of rows

int n;             // no of columns

for(int i=0;i<m;i++)             //for loop to access the row

{

     for(int j=0;j<n;j++)       //for loop to access the column

   {

       cin>>a[i][j];

   }

}

 

Was it useful?  




Please login to reply to this problem.



Related Problems on Fixoncloud