I have written a little program to outline my problem. It should print the values of the "ary" to the screen. If I use the "ary" directly, no problem. But I want to access "ary" through a reference:
#include <stdio.h>
#include <stdlib.h>
#define NUM_X (4)
#define NUM_Y (4)
int ary[NUM_X][NUM_Y] =
{
{11, 12, 13, 14},
{21, 22, 23, 24},
{31, 32, 33, 34},
{41, 42, 43, 44},
};
void printAry(int *ppAry[])
{
int i, j;
for(i = 0; i < NUM_X; ++i)
{
for(j = 0; j < NUM_Y; ++j)
//printf("%d\t", ary[i][j]);
printf("%d\t", ppAry[i][j]);
printf("\n");
}
}
int main()
{
int **ppAry = &(ary[0][0]);
printAry(ppAry);
return 0;
}
If you run the above program you get a runtime error, because ppAry is not the right reference, I guess. How do I change ppAry to make this work?