Initialise a 2D array matrix as follows:
#define N 3
...
int matrix[N][N] = {};
The elements of the matrix can be accessed as follows:
for(i=0; i<N; ++i)
{
for(j=0; j<N; ++j)
printf("%d ", *(*(matrix + i) + j) );
printf("\n");
}
However the following code fails with a segmentation fault.
int **matrix_pointer = (int **)matrix;
for(i=0; i<N; ++i)
{
for(j=0; j<N; ++j)
printf("%d ", *(*(matrix_pointer + i) + j) );
printf("\n");
}
Please, Explain why or suggest an alternate method (with pointers) that works.