0% found this document useful (0 votes)
17 views3 pages

2D Array

Uploaded by

brittika mondal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

2D Array

Uploaded by

brittika mondal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 3

General form of declaring N-dimensional arrays:

data_type array_name[size1][size2]....[sizeN];

data_type: Type of data to be stored in the array.


Here data_type is valid C/C++ data type
array_name: Name of the array
size1, size2,... ,sizeN: Sizes of the dimensions

Examples: Size of multidimensional arrays


Two dimensional array:
int two_d[10][20]; The array int x[10][20] can store total (10*20) = 200 elements.

Three dimensional array:


int three_d[10][20][30];
#include<iostream>
using namespace std;
First Method:
int main()
int x[3][4] = {0, 1 ,2 ,3 ,4 , 5 , 6 , 7 , 8 , 9 , 10 , 11} {
// an array with 3 rows and 2 columns.
int x[3][2] = {{0,1}, {2,3}, {4,5}};

// output each array element's value


Better Method:
for (int i = 0; i < 3; i++)
{
int x[3][4] = {{0,1,2,3}, {4,5,6,7}, {8,9,10,11}};
for (int j = 0; j < 2; j++)
{
cout << "Element at x[" << i
<< "][" << j << "]: ";
cout << x[i][j]<<endl;
}
}

return 0;
}

You might also like