Machine-translated by Google. Questions are authored in English.
Top

Discussion

On a 32-bit target with natural alignment, what is sizeof(struct s)?

struct s {
    uint8_t  a;
    uint32_t b;
    uint8_t  c;
};

  • A.6, the sum of the member sizes
  • B.8, one padding byte having been inserted
  • C.16
  • D.12

Answer: D

Three bytes of padding follow a so that b lands on a four-byte boundary, and three more follow c so the whole structure is a multiple of its strictest alignment. Reordering the members as b, a, c would bring it down to eight.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.