// An example program making use of structs. #include struct student { int zid; char first[20]; char last[20]; int program; char alias[10]; }; struct student abiram = { .zid = 5308310, .first = "Abiram", .last = "Nadarajah", .program = 3778, .alias = "abiramn" }; struct student xavier = { .zid = 5417087, .first = "Xavier", .last = "Cooney", .program = 3778, .alias = "xavc" }; int main(void) { struct student *selection = &abiram; printf("zID: z%d\n", selection->zid); printf("First name: %s\n", selection->first); printf("Last name: %s\n", selection->last); printf("Program: %d\n", selection->program); printf("Alias: %s\n", selection->alias); // What's the size of each field of this struct, // as well as the overall struct? printf("sizeof(zid) = %zu\n", sizeof(selection->zid)); printf("sizeof(first) = %zu\n", sizeof(selection->first)); printf("sizeof(last) = %zu\n", sizeof(selection->last)); printf("sizeof(program) = %zu\n", sizeof(selection->program)); printf("sizeof(alias) = %zu\n", sizeof(selection->alias)); // What's the size of the overall struct? printf("sizeof(struct student) = %zu\n", sizeof(struct student)); // We can see that two extra padding bytes were added to the end // of the struct, to ensure that the next struct in memory is aligned // to a word boundary. return 0; }