一、结构体类型
1、构造结构体类型
struct 结构体类型名
{成员1的定义;
成员2的定义;
成员n的定义;
};
例如:
struct student
{int sn;
int age;
char sex;
int s[3];
};
注:
(1)定义成员的方式与定义普通变量的方式一样。
(2)成员列表必须用一对花括号括起。
(3)结构体名可以省略。
2、定义结构体变量
三种格式
A.先定义(构造)结构体类型名再定义结构体变量
例如:
main()
{
struct student//类型名
{int sn;
int age;
char sex;
int s[3];
};
/*类型定义*/
struct student stul,stu2,st[25];/*变量定义*/
}
B.在定义结构体类型的同时可以定义结构体变量
例如:
struct student
{int sn;
int agc;
char sex;
int s[3];
}stul,stu2,st[25];
<