例如,有一种结构
struct A
{
char a;
int i;
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我们有[1字节] +填充[3字节] + int [4字节] = 8.
现在让我们对上面的struct进行一些更新,
struct A
{
int i;
char a;
};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,char来自int并且不需要添加填充字节,这意味着sizeof(A)= 5字节,但在这种情况下我也得到8字节的结果.为什么?
好的,这个案子呢
struct s
{
int b;
double c;
char a;
};
Run Code Online (Sandbox Code Playgroud)
根据下面给出的逻辑,有一个:size = b[4 bytes] + padding[4 bytes] + c[8] + a[1] + padding[7 bytes to align with double] = 24,但执行后我得到16.这怎么可能?