这两个程序为何不一样
#define N 4
int fun(int (*p)[N],int m,int *q)
{int i=0,n,*s;
n=N*m;
s=(int *)p;
for(i=0;i<n;i++)
*(q+i)=*(s+i);
return n;
}
main()
{int a[5][N]={{11,12,13,14},{21,22,23,24},{31,32,33,34},{41,42,43,44},{51,52,53,54}},b[20]={0},i,len;
len=fun(a,5,b);
for(i=0;i<len;i++)
{printf("%4d",b[i]);
if(i%4==3)
printf("\n");
}
}
****************************************************
#define N 4
int fun(int (*p)[N],int m,int *q)
{int i=0,n;
n=N*m;
p=(int *)p;
for(i=0;i<n;i++)
*(q+i)=*(p+i);
return n;
}
main()
{int a[5][N]={{11,12,13,14},{21,22,23,24},{31,32,33,34},{41,42,43,44},{51,52,53,54}},b[20]={0},i,len;
len=fun(a,5,b);
for(i=0;i<len;i++)
{printf("%4d",b[i]);
if(i%4==3)
printf("\n");
}
}