Code example to output the elements of a multidimensional array, using 2 nested for-loops. Each position of the array is assigned a value.
#include <iostream>
using namespace std;
int main() {
int myArray[2][4];
myArray[0][0] = 1;
myArray[0][1] = 2;
myArray[0][2] = 3;
myArray[0][3] = 4;
myArray[1][0] = 5;
myArray[1][1] = 6;
myArray[1][2] = 7;
myArray[1][3] = 8;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
cout << myArray[i][j];
}
cout << endl;
}
return 0;
}
1234
5678