Consider the following code
#include<stdio.h>
void main()
{
int s[4][2] =
{
{20,1},
{21,2},
{22,3},
{23,5}
};
int (*p)[2];
int i,j,*pint;
for( i=0;i<=3;i++)
{
p=&s[i];
pint= (int *)p;
for(j=0;j<=1;j++)
{
printf("%d \n", *(pint + j));
}
}
}
The code basically creates a 2-D array, then creates a pointer to 1-D array. Then the pointer to the 1-D array is initialized with the code p = &s[i];
The next line initializes a pointer to an integer 'pint'. pint = (int *)p;
I was wondering why the following line of code doesn't work. It makes logical sense. pint = p;
It will not compile.
It should be
See the working code here: http://ideone.com/CvNlxG