不用
struct Teacher
{
int age;
char name[30];
};
struct Teacher t;
使用
typedef struct Teacher
{
int age;
char name[30];
}Teacher;
Teacher t;
说明
typedef struct student{
char name[20];
int age;
char class;
}student_1;
这语句实际上完成两个操作:
- 定义一个新的结构类型
struct student{
char name[20];
int age;
char class;
};
2) typedef为这个新的结构起了一个名字,叫student_1。
typedef struct student student_1; (对比typedef int student_1来进行理解)
因此,student_1实际上相当于struct student,这样定义一个变量的时候,既可以用struct student aaa,也可以用student_1 aaa。student_1成了一个数据类型。