私はC言語を勉強していて、構造体についていくつか学ぼうとしています。以下にこの例を示し、構造体のメモリ割り当てがどのように構成されているかを確認しようとしています。構造体のすべてのフィールドが単語化されているため、十分なメモリが使用されていない場合は、例に示されているはずの空のメモリスペースがありますが、コンパイラは、型指定子がない、期待される'、および型のようないくつかのエラーを返します。名前は指定子または修飾子を必要とします。どうして?
#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;
}