xxxxxxxxxx
// Two dimensional array
int a[2][3]= {
{1, 2, 3},
{4, 5, 6}
};
cout << a[1][1]; // Output is 5
// Three dimensional array
//[2] is elements; [3] is rows in elements; [4] is column in elemnents
int a[2][3][2]= {
//Element 0
{ {1, 2},
{2, 3},
{4, 5}
},
// Element 1
{ {6, 7},
{8, 9},
{10, 11}
}
};
cout << a[0][1][1]; // Prints 3
2-Dimensional Array
xxxxxxxxxx
c
Copy code
#include <stdio.h>
#define ROWS 3
#define COLS 4
int main() {
// Declaration and initialization of a 2-dimensional array
int matrix[ROWS][COLS] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
// Printing the elements of the 2-dimensional array
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}