#include <stdio.h> typedef struct { char a;//1 int b;// 4 short c;// 2 } MyStruct; void print_offsets() { MyStruct mystruct; printf("Offset of a: %d\n", sizeof(mystruct.a)-1); printf("Offset of b: %d\n", sizeof(mystruct.b)); printf("Offset of c: %d\n", sizeof(mystruct.c)+6); printf("Size: %d\n", sizeof(mystruct)); } 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