#include <stdio.h>
#include <stddef.h>
struct Address {
char name[16];
char street[32];
int entry;
};
int main() {
printf("name offset = %zd bytes from start of struct \n", offsetof(struct Address, name)); // 0
printf("street offset = %zd bytes from start of struct \n", offsetof(struct Address, street)); // 0 + 16 = 16
printf("phone offset = %zd bytes from start of struct \n", offsetof(struct Address, entry)); // 16 + 32 = 48
return 0;
}
/*
run:
name offset = 0 bytes from start of struct
street offset = 16 bytes from start of struct
phone offset = 48 bytes from start of struct
*/