结构:一种构造的数据类型
声明结构一般形式:
struct 结构类型名
{
成员表
};
struct StudentType
{
intnum;
char*name;
charsex[3];
floatscore;
};
结构类型变量的定义
1:先声明再定义
struct 结构类型名
{
成员表
};
struct 结构类型名 结构变量表;
struct StudentType
{
intnum;
char*name;
charsex[3];
floatscore;
};
struct StudentType boy,girl;
struct StudentType student[3];//定义结构类型数组
2:先声明的同时定义
struct 结构类型名
{
成员表;
}结构变量表;
struct StudentType
{
intnum;
char*name;
charsex[3];
floatscore;
}boy,girl;//student[3],结构类型数组
3:直接定义
struct
{
成员表
}结构变量表;
struct
{
intnum;
char*name;
charsex[3];
floatscore;
}boy,girl;//student[3];结构类型数组。
嵌套的结构类型
struct DateType
{
intyear;
intmonth;
intday;
};
struct StudentType
{
intnum;
char*name;
charsex[3];
structDateType birthday;
floatscore;
}boy,girl;
结构类型变量可定义时直接初始化
struct StudentType student=
{
1010;
“德华”;
“男”;
{1993,6,18};
99.8;
};
指针访问结构类型变量各个成员
(*结构类型指针变量).成员名
结构指针变量->成员名