
Tridip C. answered 08/08/20
5+ years of Experience in Programming in C/C++
For mystruct_A, its elements are padded so that each one of them are aligned with the 4 byte boundary.
Similarly, for mystruct_B, the elements are padded so that each one of them are aligned with the 4 byte boundary.
Thus their sizes are 12 bytes and 8 bytes respectively.
Here, the compiler is NOT doing any optimization by packing the members. With such optimization, the packed structure would become
The size of x_packed would be 8 bytes.