我是C的新手所以"分配"可能不适合在这里使用。
假设我有一个这样的函数,它返回指向int的指针。
int **foo(){} //I wouldn't care much what this function does
在main()函数中我定义了一个像这样的数组
int playground[10][10];
playground=foo();
但是编译器警告我这个错误:
使用数组类型赋值给表达式 playground = foo();
这里究竟出了什么问题?据我所知,因为 playground 是一个二维数组所以它将是一个指向int指针的指针,它正是 foo()返回的函数。
有人可以解释一下吗?非常感谢!
答案 0 :(得分:0)
数组不是指针。特别是,数组不是可赋值的左值,因此数组名称永远不能在赋值语句的左侧单独使用。你想要:
int **playground;
playground = foo();