【发布时间】:2015-02-18 09:32:47
【问题描述】:
我正在阅读 C++ 中的数组。我尝试了以下代码:
int main()
{
int a[10];
int *p;
p = &a;
}
我得到编译器错误:
pointers.cpp:10:6: error: cannot convert ‘int (*)[10]’ to ‘int*’ in assignment
p = &a;
为了理解能够分配给指针的数组类型,我尝试了以下代码:
int main()
{
int a[10];
int *r[10];
r = a;
}
编译错误:
: error: incompatible types in assignment of ‘int [10]’ to ‘int* [10]’
r = a;
然后我尝试了这个:
int main()
{
int a[10];
int *r[10];
r = &a;
}
编译错误:
error: incompatible types in assignment of ‘int (*)[10]’ to ‘int* [10]’
r = &a;
int (*)[10] 是什么类型?
【问题讨论】:
-
@dandan78 问题是关于 C++,而不是关于 C。数组在两种语言中的工作方式并不完全相同。
-
如果您不知道自己在做什么,请不要尝试使用 C++。你的房子可能会倒塌。