#include <stdio.h>
int main()
{
int a[5];
int i;
for (i=0; i<5; i++)
a = i;
for (i=0; i<5; i++)
printf("a[%d] = %d\n", i, a);
}
最佳答案
用作运算符操作数的数组(sizeof
和一元 &
除外)会自动转换为指向数组第一个元素的指针。
转换后的指针不是左值,因此不能用作赋值运算符的左操作数。
此代码有效。
#include <stdio.h>
int main(void)
{
int a[5];
int i;
for (i=0; i<5; i++)
a[i] = i;
for (i=0; i<5; i++)
printf("a[%d] = %d\n", i, a[i]);
return 0;
}
关于c - 为什么在 howstuffworks.com 上发布的这段代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36096507/