一般形式
struct结构体名
{
类型名1 成员名1;
类型名2 成员名2;
类型名n 成员名n;
};
定义结构体类型的变量
方法一:定义结构体类型时同时定义该变量;
struct student
{
char name[10];
char sex;
int age;
}stu1, *ps, stu[5]; /*stu1, *ps, stu[5]为结构体类型变量*/
方法二:先定义结构体类型,再定义该变量;
1 struct student
2 {
3 char name[10];
4 char sex;
5 int age;
6 };
7
8 struct student stu1, *ps, stu[5];
方法三:用typedef先给结构体类型命别名,再用别名定义变量
1 #include <stdio.h>
2
3 struct student
4 {
5 char name[10];
6 char sex;
7 int age;
8 };
9
10 typedef struct student STU;
11
12 STU stu1, *p, stu[10];