c struct 对齐
What we know is that size of a struct is the sum of all the data members. Like for the following struct,
我们知道的是, 结构的大小是所有数据成员的总和 。 对于以下结构,
struct A{
int a;
int* b;
char c;
char *d;
};
Size of the struct should be sum of all the data member, which is: Size of int a+ size of int* b +size of char c+ size of char* d
结构的大小应为所有数据成员的总和,即:int a的大小+ int * b的大小+ char c的大小+ char * d的大小
Now considering the 64-bit system,
Size of int is 4 Bytes
Size of character is 1 Byte
Size of any pointer type is 8 Bytes
(Pointer size doesn't depend on what kind of data type they are pointing too)
So the size of the struct should be: (4+8+1+8)=21 Bytes
Let's see what compiler is giving using the <