I have 5 different 2d Arrays in contrast to the normal usage of 2d Arrays.
int A[1][2] = {2, 5};
int B[1][2] = {6, 1};
int C[1][2] = {4, 8};
int D[1][2] = {3, 6};
int E[1][2] = {9, 7};
Then I have declared an array of Pointers to these 5 arrays by:
typedef int (*PointerToArrays)[2];
static PointerToArrays arr[POPULATION_SIZE] = {A, B, C, D, E};
Now I want to print the elements of these arrays by the following method:
for(int i=0; i<10; i++) {
for(int j=0; j<2; j++) {
cout << (*arr)[i][j] <<endl;
}
}
But I am getting the following results:
2
5
4197162
0
6
1
4197245
0
4
8
You can see that the 1st and 2nd elements are fine, then the next two are garbage. Then the next two are fine and next two are garbage and so on...
What am I doing wrong? How to I print out the values of A, B, C, D and E respectively using a "for" loop?