不用
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成了一个数据类型。
博客介绍了C语言中使用typedef定义结构体类型的方法。对比了不用和使用typedef定义结构体变量的方式,还说明了typedef struct语句完成定义新结构类型和为其命名两个操作,使新名字成为一个数据类型,可用于定义变量。
2568

被折叠的 条评论
为什么被折叠?



