【发布时间】:2012-11-06 12:08:14
【问题描述】:
可能重复:
Sizeof an array in the C programming language?
Why sizeof(param_array) is the size of pointer?
void printSizeOfArray(int a[])
{
printf("%lu\n", sizeof(a));
}
int main()
{
int it;
int a[4] = {0};
printSizeOfArray(a);
return 0;
}
当我运行代码时,我得到 8。为什么指向数组的指针是 void 类型的指针?
如果指向数组的指针是 void 类型,为什么,当我写的时候:
int *it;
int a[4] = {0};
it = a;
printf("%lu\n", sizeof(it));
它也可以吗?如何使用int 指点?
另外,为什么它在第二个中打印 8 而不是 4?它是指向数组 (void*) 的指针,而不是 int。
【问题讨论】:
-
为什么你一直说指向数组的指针是 void 类型的? “数组指针”的类型取决于数组中的内容。
-
Why is a pointer to an array a pointer of type void?这个问题的第一个问题是你的第一个代码块中没有指针......第二个整体问题pointers are not arrays, arrays are not pointers. -
Why is a pointer to an array a pointer of type void?哪里来的?
标签: c arrays pointers sizeof void