struct abc {
int x;
int y;
char a;
char b;
};
int main() {
struct abc test;
printf("%d", sizeof(test));
}
The output of my code is not as I expected, I expected that the output will be 16
, because as I think those variables will be stored on the memory as follows :
--------|-------|---------------|
| | | | | | | | | | | | | | | | |
--------|-------|-|-|-----------|
x | y |a|b| 6 bytes
after the first 8 bytes we will have two bytes for the two characters so the compiler need to add 6 bytes of memory, because the processor need to take 8 ytes on each cycle time.
Anyway the output is 12
, so I want to know where is the problem here.
Note that: I work with 64-bit processor, in my system the size of int
is 4 bytes and the size of char
is 1 byte.