nam*_*ked 3 c structure unions
所有,
这是一个关于联盟的例子,我觉得这很令人困惑.
struct s1
{
int a;
char b;
union
{
struct
{
char *c;
long d;
}
long e;
}var;
};
Run Code Online (Sandbox Code Playgroud)
考虑到char1个字节,int是2个字节,long是4个字节.这里整个结构的大小是多少?联合大小是{size of char*} + {size of double}?我很困惑,因为结合包裹在结合中.
另外,我如何访问dstruct中的变量. var.d?