The size of a structure is the sum of the sizes of it's members, plus some optional padding necessary to preserve alignment. The amount of padding usually depends on the alignment of the largest primitive data type in the struct (int, char, float, double, pointer).
Code:
#include <stdio.h>
#include <stddef.h>
int main(){
struct a{
int x;
char y[10];
};
struct b{
char y[10];
int x;
};
printf("%zd\n", sizeof(struct a));
printf("%zd\n", sizeof(struct b));
printf("%ld\n", offsetof(struct a,x));
printf("%ld\n", offsetof(struct a,y));
printf("%ld\n", offsetof(struct b,y));
printf("%ld\n", offsetof(struct b,x));
}
$ ./a.out
16
16
0
4
0
12
In struct a, the padding is at the end of the structure.
In struct b, the padding is between the array of chars and the int.