如果一个数组名作为指针处理,递增一个数组时,为什么我得到的左值的一个编译时错误要求?
问题描述:
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).