关于函数返回二维数组的问题
int** get()
{
int temp[3][3] =
{
{3, 2 ,1},
{0, 0, 0},
{0 ,0 ,0}
};
return temp; // 报错:返回值类型与函数类型不匹配
}
int** get()
{
int temp[3][3] =
{
{3, 2 ,1},
{0, 0, 0},
{0 ,0 ,0}
};
return temp; // 报错:返回值类型与函数类型不匹配
}
一般没这么玩的.
#include <stdio.h>
int (*get())[3]
{
static int temp[3][3] = {{3, 2, 1}, {0, 0, 0}, {0, 0, 0}};
return temp;
}
int main()
{
int(*ptr)[3] = get();
for (int i = 0; i != 3; ++i)
{
for (int j = 0; j != 3; ++j)
{
printf("%d\n", ptr[i][j]);
}
}
}