#include <stdio.h> typedef struct { char a; int b; short c; } MyStruct; void print_offsets() { MyStruct m; printf("Offset of a: %d\n", (int)((long int)(&m.a) - (long int)(&m))); printf("Offset of b: %d\n", (int)((long int)(&m.b) - (long int)(&m))); printf("Offset of c: %d\n", (int)((long int)(&m.c) - (long int)(&m))); printf("Size: %d", sizeof(m)); } int main() { print_offsets(); return 0; }
Test Cases
Test Results
Input
Expected Output
Offset of a: 0 Offset of b: 4 Offset of c: 8 Size: 12