The size of structure in C

1 · 0x4c2 · Nov. 25, 2020, 6:38 a.m.
The sizeof for a struct is not always equal to the sum of sizeof of each individual member. This is because of the padding added by the compiler to avoid alignment issues. Padding is only added when a structure member is followed by a member with a larger size or at the end of the structure. Different compilers might have different alignment constraints as C standards state that alignment of structure totally depends on the implementation. Case 1: 1struct A { 2 // sizeof(int) = 4 3 ...