ProAnswers.org

Why does the 'sizeof' operator return a size larger for a structure than the total sizes of the structure's members?

Why does the ‘sizeof’ operator return a size larger for a structure than the total sizes of the structure’s members?

This is because of structure alignment. Structure alignment refers to the ability of the compiler to insert unused memory into a structure so that data members are optimally aligned for better performance. Many processors perform best when fundamental data types are stored at byte-addresses that are multiples of their sizes.

a struct can (but usually doesn’t) have virtual functions, in which case the size of the struct will also include the space for the vtbl.