<分区>
我有一个结构:
struct Thing {
int id;
}
然后我创建一个 Thing
数组:
struct Thing *a;
a = (struct Thing *) malloc(sizeof(struct Thing));
a->id = 1;
struct Thing *b;
b = (struct Thing *) malloc(sizeof(struct Thing));
b->id = 2;
struct Thing *array[] = {a,b};
我检查数组的大小是 2。 我通过以下方式检查数组的大小:
printf("%d",sizeof(array)/sizeof(array[0]));
我还有一个函数接收一系列事物:
void function(struct Thing *array[]) {
//do stuff
}
然后我将数组传入函数:
function(array);
在函数内部,数组的大小为 1。 有人可以指出我哪里出错了吗?为什么函数内部数组 1 的大小?