我正在学习 C 语言并尝试学习一些有关 Structs 的知识,我在下面有这个示例,我试图了解结构内存分配是如何组成的。我了解到结构中的每个字段都是字长的,因此如果没有使用足够的内存,将会有空的内存空间,这应该在示例中看到,但是编译器给了我几个错误,例如Type specifier missing、Expected '和Type名称需要说明符或限定符。怎么来的?
#include <stddef.h>
#include <stdio.h>
typedef struct
{
char name[25];
int id;
int year;
char material;
} Student;
int
main(void)
{
Student talu;
printf("Size of tAlu %d\n", (int)sizeof(talu));
printf("name size is %d\n", offsetof(talu, name));
printf("id size is %d\n", offsetof(talu, id));
printf("year size is %d\n", offsetof(talu, year));
printf("material size is %d\n", offsetof(talu, material));
return 0;
}