content

for the below struct:

typedef struct Human{
    char first_initial;
    int age;
    double height;
} human_t;

in memory it would be: source: boot.dev

  • 32 bit processor processes memory in a group of 32 bits (4 bytes)
  • for memory size smaller than 32 bits, it adds padding
  • as a general rule of thumbs, ordering fields in a struct from largest to smallest will help the compiler minimize padding.

up

down

reference