c中如何返回一个指向二维数组的指针
#include <stdio.h>
#include <stdlib.h> #define COUNT 3 typedef int (*Mystype)[COUNT]; Mystype yourfunction(int n)
{
Mystype p;
int i = , j = ;
if (NULL==(p = (Mystype)malloc(n*COUNT*sizeof(int))))
{
printf("OVERFLOW!\n");
exit();
}
for (; i<n; i++)
{
for (j=; j<COUNT; j++)
{
p[i][j] = j+; // p[i][j] == *(*(p+i)+j);
}
}
return p;
} void print_array(Mystype arry, int n)
{
int i = , j = ;
for (; i<n; i++)
{
for (j=; j<COUNT; j++)
{
printf("%d ",arry[i][j]); // arry[i][j] == *(*(arry+i)+j);
}
printf("\n");
}
} void main()
{
int n = ;
Mystype a = yourfunction(n);
print_array(a,n);
}