#include<iostream>
using namespace std;
union B
{
long i;
int k[5];
char c;
}B1;
struct A
{
int a;
union B b;
double dog;
}A1;
void main()
{
cout<<sizeof(A1)+sizeof(B1)<<endl;
using namespace std;
union B
{
long i;
int k[5];
char c;
}B1;
struct A
{
int a;
union B b;
double dog;
}A1;
void main()
{
cout<<sizeof(A1)+sizeof(B1)<<endl;
}
输出结果 52
B 中最长是int k[5] : 20字节
sizeof(B1)=20;
A中 union B b; 不是20 而是 5个int 所以最长是double 8个字节
sizeof(A1)=32 6个int 刚好拼成 3个double