Below program (a toy program to pass around arrays to a function) doesn\'t compile. Please explain me, why is the compiler unable to compile(either because of techni
In your code the double pointer is not suitable to access a 2D array because it does not know its hop size i.e. number of columns. A 2D array is a contiguous allotted memory.
The following typecast and 2D array pointer would solve the problem.
# define COLUMN_SIZE 4
void print2(int ** array,int n,int m)
{
// Create a pointer to a 2D array
int (*ptr)[COLUMN_SIZE];
ptr = int(*)[COLUMN_SIZE]array;
int i,j;
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
printf("%d ", ptr[i][j]);
printf("\n");
}
}