#include<stdio.h>
void main()
{
int a[]={1,2,3,4};
int b[]={5,6,7};
int *p[2];
p[0]=a;
p[1]=&b + 1;
printf("%d\n%d",&p[1][0],p[0][1]);
}
Here p is a 1darray of pointers, then how come a 2d array is used in the printf statement.
Also the output is 1 2
Please help me.
This code doesn’t make any sense to me. First you declare int *p[2] and then in one line you write p[1]=&b+1. How does this make sense?
The code is not correct. It has error, see here.
p is an array of integer pointers and thus by p[0], we are setting p[0] as pointing to a i.e. array a. And thus p0 is 2 i.e. 2nd element of array a as 2-d arrays p[row][col] are also treated like 1-d array having (row) rows where each row has (col) elements. Thus p0 is *(p[0]+1) which is *(a+1) which is 2. Hope it helps!