结构体定义 typedef struct 用法详解和用法小结

转https://blog.csdn.net/qq_41848006/article/details/81321883
node 结点
typedef 是类型定义的意思 typedef struct 是为了使用这个结构体方便.
区别在于 : 若struct node{}这样来定义结构体变量时,需要:
struct node n;
若用typedef :
typedef struct node{}NODE
在申请变量时就可以 : NODE n;
其实就相当于 NODE是node的别名,区别在于是否可以使用struct这个关键字

eg1: //在c中定义一个结构体类型时如果要用到typedef
typedef struct Student
{
int no;
char name[12];
}Stu,student;

在声明变量时就可,Stu stu1;或者 student stu2;(Stu 和 student同时为Student的别名)

无typedef::
struct Student
{
int no;
char name[12];
}Stu;

则必须用struct Student stu1;或者struct Stu stu1;来声明

posted @ 2021-03-27 19:19  菜鸟本鸟gyh  阅读(1414)  评论(0)    收藏  举报