Sunday, Nov 18th

Last update12:59:40 PM GMT

Why do structures get padded? Why does sizeof() return a larger size?

Write e-mail

Padding is used so that the processor can access structure members faster. If they are not aligned (say to word boundaries), then accessing them might take up more time.


This also ensures that alignment properties are preserved when an array of contiguous structures is allocated. Even if the structure is not part of an array, the end padding remains, so that sizeof() can always return a consistent size.

Share this post

Web Hosting