1.使用结构体的情况:需要将不同类型的数据组合在一起,比如一个学生的学号,电话,qq等
2.结构体类型声明格式:struct 结构体类型名{成员表}
struct Date
{int month;
int day;
int year;
}
struct Student
{int num;
chat name[20];
float score;
Date birthday; //Date是结构体类型,birthday是Date类型的成员
}
成员也叫域,成员表也叫域表;
c++中,成员可以是函数,可以是结构体变量 如上述birthday
3.定义结构体类型变量
Student student1,student2; //先定义结构体类型,再定义变量
或者struct Student{ };student1,student2;
4.结构体变量的初始化:Student student1={30002,Mike, ,};
5.引用结构体变量中成员的格式:结构体变量名.成员名
student1.num=1001;//"."是成员运算符,优先级最高