Interview Questions

Why does sizeof report a larger size than I expect for a structure type ...

C Interview Questions and Answers


(Continued from previous question...)

Why does sizeof report a larger size than I expect for a structure type ...

Q: Why does sizeof report a larger size than I expect for a structure type, as if there were padding at the end?

Padding at the end of a structure may be necessary to preserve alignment when an array of contiguous structures is allocated. Even when the structure is not part of an array, the padding remains, so that sizeof can always return a consistent size.

(Continued on next question...)

Other Interview Questions