struct BOOK
{
char name[120];
char author[120];
int year[50];
};
int main (void)
{
int i;
int number;
struct BOOK* books;
number = 50000;
printf("before \nsizeofbooks %d \n sizeofBOOK %d\n",
sizeof(books), sizeof(struct BOOK));
books = (struct BOOK*)malloc(sizeof(struct BOOK) * number);
printf("sizeofbooks %d \n sizeofBOOK %d\n",
sizeof(books), sizeof(struct BOOK));
free(books);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
before
sizeofbooks 4
sizeofBOOK 440
after
sizeofbooks 4
sizeofBOOK 440
Run Code Online (Sandbox Code Playgroud)
它总是输出4,即使我写入不同的数组,但我希望它会改变.我究竟做错了什么?
我的操作系统是winxp 32位,我使用的是代码块.
| 归档时间: |
|
| 查看次数: |
206 次 |
| 最近记录: |