What does ptr[0] point at ?
Answer - nothing.
Just because you can use two subscripts on both of them doesn't make them equivalent or freely interchangeable.
> ptr = &array[0][0];
Did you get a warning for this. You should have, and it's a big clue that something is wrong.
Here are a couple of things which should work.
Code:
#include <stdio.h>
int main(void)
{
int **ptr;
int a, b, i, j;
int array[2][4] = {{1,2,3,4}, {5,6,7,8}};
int *parr[2] = { array[0], array[1] };
ptr = parr;
for(i=0; i<=1; i++)
{
for(j=0; j<=3; j++)
{
printf("%d\n", *(*(ptr + i) + j) );
}
}
}
#include <stdio.h>
int main(void)
{
int (*ptr)[4];
int a, b, i, j;
int array[2][4] = {{1,2,3,4}, {5,6,7,8}};
ptr = array;
for(i=0; i<=1; i++)
{
for(j=0; j<=3; j++)
{
printf("%d\n", *(*(ptr + i) + j) );
}
}
}