如果一个数组名作为指针处理,递增一个数组时,为什么我得到的左值的一个编译时错误要求? [英] If an array name is treated as a pointer, why do I get a compile time error of Lvalue required when incrementing an array?
本文介绍了如果一个数组名作为指针处理,递增一个数组时,为什么我得到的左值的一个编译时错误要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int main()
{
int a[]={2,3,4,5,6};
int j;
for(j=0;j<5;j++)
{
printf("%d\n",*a);
a++;
}
return;
}
给出左值
要求的错误,但
int main()
{
int a[]={2,3,4,5,6};
int *p,j;
p=a;
for(j=0;j<5;j++)
{
printf("%d\n",*p);
p++;
}
return;
}
没有。为什么????
doesn't. why????
推荐答案
虽然密切相关,阵列不是指针的。数组的名字只是一个标签(当您试图对其进行修改,因此,左侧的运算错误),以确定一些分配的内存。
Though closely related, arrays are not pointers. The name of the array is just a label to identify some allocated memory (hence, the Lvalue error when you try to modify it).
这篇关于如果一个数组名作为指针处理,递增一个数组时,为什么我得到的左值的一个编译时错误要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文