sizeof operator, im confused
good day guys,
i have this code
Code:
#include <stdio.h>
int main(){
struct a{
int x;
char y[10];
};
struct a aa;
printf("%d", sizeof(aa));
}
when i run it the output is
when i change sizeof aa to sizeof aa.x the output is 4 which is understandable since member X is an int.
when i changed it to sizeoff aa.y the output is 10 which is also understandable, however when its sizeof aa its output is 16.
why?? :frown:
i read that by design, the memory allocated for each member is == to memory allocated for the largest member so in that case the sizeoff aa ought to return 20 since char y[10] is the largest member occupying 10bytes.
what i'm i missing?