结构体声明
struct student{
char name[20]; //姓名
int num; //学号
char sex; //性别
unsigned age; //年龄
}; //最后用一个分号结尾
struct student student1; //定义一个学生结构体变量
student student1; //正确定义方式
struct student{
char name[20];
int num;
char sex;
unsigned age;
}std1,std2,std3; //声明的同时定义多个结构体变量
使用成员操作符(.圆点)访问结构体变量的成员,如:student.name。
结构体初始化
student std1={"a","b",...};
或
struct student{
。。。
。。。
}std2={...};
定义结构体数组
struct score{
...
...
}std[5];
或
score std[5];
结构体指针
struct score{
char ...
short ...
...
} *pscore1;
或
score *pscore2;
结构体指针的引用
pscore1->num; pscore->math;
或
(*pscore).num; (*pscore).math;
共用体
union <共用体类型名>{
成员列表;
};