struct类型以其中所有size大小之和为其大小
#include
<
iostream
>
using namespace std;
int main()
{
typedef union {long i; int k[5]; char c;} DATE;
struct data { int cat; DATE cow; double dog;} too;
DATE max;
cout<<"sizeof(struct date)+sizeof(max) = "<<sizeof(too)+sizeof(max)<<endl;
cout<<"sizeof(too) = "<<sizeof(too)<<endl;
cout<<"sizeof(max) = "<<sizeof(max)<<endl;
cout<<"struct data.cow size = "<<sizeof(too.cow)<<endl;
cout<<"union DATE.i size = "<<sizeof(max.i)<<endl;
cout<<"union char.c size = "<<sizeof(max.c)<<endl;
}
using namespace std;
int main()
{
typedef union {long i; int k[5]; char c;} DATE;
struct data { int cat; DATE cow; double dog;} too;
DATE max;
cout<<"sizeof(struct date)+sizeof(max) = "<<sizeof(too)+sizeof(max)<<endl;
cout<<"sizeof(too) = "<<sizeof(too)<<endl;
cout<<"sizeof(max) = "<<sizeof(max)<<endl;
cout<<"struct data.cow size = "<<sizeof(too.cow)<<endl;
cout<<"union DATE.i size = "<<sizeof(max.i)<<endl;
cout<<"union char.c size = "<<sizeof(max.c)<<endl;
}