共用体在形式上和结构体很相像,可以理解为精简版的结构体
共用体中可以存放不同类型的数据,但是每次智能存放一个类型的数值
共用体所占用的内存空间跟成员中所需的最大空间的size保持一致
枚举类型
// arrstruct.cpp -- an array of structures
#include <iostream>
struct inflatable
{
char name[20];
float volume;
double price;
};
int main(void)
{
using namespace std;
inflatable guests[2] =
{
{"Bambi", 0.5, 21.99},
{"Godzilla", 2000, 565.99}
};
cout << "The guests " << guests[0].name << " and " << guests[1].name
<<"\nhave a combined volume of "
<< guests[0].volume + guests[1].volume << "cubic feet. \n";
return 0;
}