Displaying Arrays using pointers instead of subscripts

I'm writing a code that is suppose to display the sum of two arrays added together into one array. Also The results are suppose to be displayed using subscripts and pointers. I have the subscript part down, but on the pointer part I am getting an error that says: C2440: '=' : cannot convert from 'int[4][5]' to 'int*'. Why can it not convert the array and how would I go about fixing this? The error is being shown in line 12.

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
srand((unsigned)time(0));
const int numRows=4, numCols=5;
int A[numRows][numCols]={0}, B[numRows][numCols]={0};
int C[numRows][numCols];
int *ArrayPointer;

ArrayPointer = C;

for (int i=0; i<numRows; i++)

{
for (int j=0; j<numCols; j++)
{
A[i][j]=rand();
B[i][j]=rand();
C[i][j]=A[i][j] + B[i][j];
cout << C[i][j] << "\t";
}
cout << endl;
}

cout << *ArrayPointer << "\t";

system("pause");

return 0;
}


This will work for the initial assignment. Multi-Dimensional arrays are more complex. You can't assign the name of the MD array to a pointer as you can with a 1D array. To be honest I'm not really sure I understand that and since I rarely use MD arrays I have never thought much about it. You should search around for more threads and articles. This issue has been discussed numerous times.
ArrayPointer = &C[0][0];
Thank you for the advice
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

  int a[3] = {1,2,3};
  for(int i=0; i<3; i++) cout << *(a+i) << "\n"; //1-D array pointer access

  int b[3][3] = {
  {1,2,3},
  {4,5,6},
  {7,8,9}
  };

  for(int i=0; i<3; i++) {
    for(int j=0; j<3; j++) cout << *(*(b+i)+j); //2-D array pointer access
    cout << "\n";
  }

Topic archived. No new replies allowed.