1int a[2][3]= {
2 {1, 2, 3},
3 {4, 5, 6}
4 };
5
6 cout << a[1][1]; // Output is 5
1int** arr = new int*[10]; // Number of Students
2int i=0, j;
3for (i; i<10; i++)
4 arr[i] = new int[5]; // Number of Courses
5/*In line[1], you're creating an array which can store the addresses
6 of 10 arrays. In line[4], you're allocating memories for the
7 array addresses you've stored in the array 'arr'. So it comes out
8 to be a 10 x 5 array. */
1#include <iostream>
2using namespace std;
3int main(){
4 int n,m;
5 int a[n][m];
6 cin >> n >>m;
7 for ( int i=0; i<n; i++){
8 for (int j=0; j<m; j++){
9 cin >> a[i][j];
10 }
11 }
12
13 for ( int x=0; x<n; x++){
14 for (int y=0; y<m; y++){
15 cout << "a[" << x << "][" << y << "]: ";
16 cout << a[x][y] << endl;
17 }
18 }
19 return 0;
20}
1
2int main()
3{
4 int row = 5; // size of row
5 int colom[] = { 5, 3, 4, 2, 1 };
6
7 vector<vector<int> > vec(row); // Create a vector of vector with size equal to row.
8 for (int i = 0; i < row; i++) {
9 int col;
10 col = colom[i];
11 vec[i] = vector<int>(col); //Assigning the coloumn size of vector
12 for (int j = 0; j < col; j++)
13 vec[i][j] = j + 1;
14 }
15
16 for (int i = 0; i < row; i++) {
17 for (int j = 0; j < vec[i].size(); j++)
18 cout << vec[i][j] << " ";
19 cout << endl;
20 }
21}
1#include <array>
22 #include <iostream>
33
44 using namespace std;
55
66 //remember const!
77 const int ROWS = 2;
88 const int COLS = 3;
99
1010 void printMatrix(array<array<int, COLS>, ROWS> matrix){
1111 //for each row
1212 for (int row = 0; row < matrix.size(); ++row){
1313 //for each element in the current row
1414 for (int col = 0; col < matrix[row].size(); ++col){
1515 cout << matrix[row][col] << ' ';
1616 }
1717 cout << endl;
1818 }
1919 }
1void printMatrix(array<array<int, COLS>, ROWS> matrix){
2for (auto row : matrix){
3//auto infers that row is of type array<int, COLS>
4for (auto element : row){
5cout << element << ' ';
6}
7cout << endl;
8}