Possible Duplicate:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
I have the next code:
#include <stdio.h>
#include <stdlib.h>
typedef struct Test
{
int a;
int b;
char c;
} Test;
int main(void)
{
Test *obj = (Test*)malloc(sizeof(Test));
printf("Size results:\r\n\r\nstruct: %i\r\nint #1: %i\r\nint #2: %i\r\nchar #1: %i\r\n",
sizeof(Test), sizeof(obj->a), sizeof(obj->b), sizeof(obj->c));
return 0;
}
The result is:
Size results:
struct: 12
int #1: 4
int #2: 4
char #1: 1
Why DOES struct size 12 bytes??? int - 4 bytes char - 1 byte
2 int + 1 char = 2 * 4 bytes + 1 byte = 9 bytes.
Why does 12 ???