#include"stdio.h" int main() { char a[5]={'A','B','C','D'}; char (*p3)[10]= &a; char (*p4)[10]= a;

为什么编译后就会出现error C2440: 'initializing' : cannot convert from 'char (*)[5]' to 'char (*)[10]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2440: 'initializing' : cannot convert from 'char [5]' to 'char (*)[10]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
求大神指导

等号左右不匹配,&a是整个数组的指针,a是数组首元素的指针,p3类型相同但是指向的数组大小不同,p4类型就不同。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-10-16
语法有问题。。。。。把程序的需求来说说

~追问

int main()
{
chara[5]={'A','B','C','D'};
char(*p3)[5]= &a;
return0;
}
他讲的是指针与数组的剖析的时候写的一个例子,我就是之前看到这个程序没有错误,所以把5变成10试一下结果就出现错误了

追答

error C2440: 'initializing' : cannot convert from 'char [5]' to 'char (*)[10]'

就是说下标出错

~

追问

不是需要强制转换吗。Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

第2个回答  2016-10-27
语法有问题。。。。。语法有问题。。。。。
相似回答