【发布时间】:2017-06-02 12:07:35
【问题描述】:
struct busData{
int busNum;
char str[SIZE+1]; //SIZE = 1000
};
int main(){
struct busData *bus = (struct busData*)calloc(5, sizeof(struct busData));
printf("\n%d", sizeof(bus)); //result is 4
free(bus);
return 0;
}
现在根据平台显示“4”或“8”。我认为它应该显示 5040 对吗?因为我用calloc() 给了5 值。那么我怎样才能得到5040呢?我一直在使用 3 个元素,直到 'bus+2' 然后我释放了 free(bus);我想知道剩下多少元素(它应该显示 2008)。所以我需要5040?
【问题讨论】:
-
什么是
SIZE? -
另外,您使用了错误的格式说明符。
标签: c pointers structure sizeof