結構體定義 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;來聲明


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM