In this code at line number 7, 'p' is a 1D pointer then how come at the print statement it is being considered as 2D pointer ? and when we do 'a+1' then it would cross whole array. I am not able to understand this code. Please explain. Expected output is
1 1 1 1
2 3 2 3
3 2 3 2
4 4 4 4
But I am getting
1 1 1 1
2 2 2 2
2 2 2 2
3 3 3 3
#include<stdio.h>
int main()
{
static int a[2][2]={1,2,3,4};
int i,j;
static int *p[]={(int*)a, (int*)a+1, (int*)a+2};
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d %d %d %d \n", *(*(p+i)+j), *(*(j+p)+i), *(*(i+p)+j), *(*(p+j)+i));
}
}
}