Im studying C language and trying to learn some about Structs, I have this example below and Im trying to see how the struct memory allocation is composed. I have learned that every field in a struct is wordsized so that if not enough memory is used there will be empty memory spaces which should be seen in the example, but the compiler gives me several error like Type specifier missing, Expected ‘, and Type name requieres specifier or qualifier. How come?
#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;
}
I also tried compiling your code and got errors, so I ended up fixing it like this:
This is with using GCC as the compiler.