The following code works, but is it OK?
#include <iostream>
using namespace std;
void display(int (*A)[3], int m, int n)
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cout << A[i][j] << endl;
}
int main()
{
int arr[][3] = {{1,2,3},{4,5,6}};
display(arr,2,3);
}
Since A is a pointer to integer array of size 3, effectively aren't we just referring to the first row? It works because the 6 elements are in contiguous locations, hence we are traversing 6 times from the address of the first item. Is my understanding correct?
arris an array of size two. where each element is itself an array of size three. All arrays are stored contiguously, whatever the element type.