Here's the scoop on the poop,
static int xx[3][4] = { {33,44,55,66},
{45,56,67,78},
{34,45,98,76}
};
main() {
printf("val = %d\n", *(*(xx+1)+2)); //same as xx[1][2]
}
Works fine... val = 67.
However,
main() {
int **pp = (int **)&xx;
printf("val = %d\n", *(*(pp+1)+2)); //same as xx[1][2]
}
Compiles without error but gives a segmentation fault at runtime. Why ?
I realize that the problem has to do with the process stack AND the fact that it is a double pointer but am unable to give a plausible explanation.
I can peel the two dim array into a one dim array using a pointer like this:
main() {
int *p = (int *)&xx;
printf("val = %d\n", *(p+6)); //same as xx[1][2]
}
Works fine when compiled and run: val = 67.
So what's the scoop in using the double pointer.
thanx,
fsm