结构体
结构体的通常形式为:
struct 结构体标签(可选)
{
类型1 标识符1;
类型2 标识符21,标识符22,标识符23;
类型3 标识符3;
}变量定义(可选);
良好的编程风格是把结构体的声明和变量的定义分开,如:
struct book {int weight,price;};
struct book book1,book2;
而不是:struct book {int weight,price;}book1,book2;
union 联合
作用1:把互相排斥的自动存储于一个联合中以便节约空间
union sex_u{
char is_male;
char is_female;
};
struct people{
char name[20];
union sex_u sex;
};
作用2:把同一个数据解释成两种不同的东西
union bits32_tag{
int whole;
struct {char c0, c1, c2, c3;} byte;
} value;
这个联合允许提取整个32位值(作为int),也可以提取单独的字节如value.byte.c2等