当前位置:网站首页>[C language syntax] the difference between typedef struct and struct

[C language syntax] the difference between typedef struct and struct

2022-07-06 05:47:00 Python's path to immortality

typedef It means type definition .
typedef struct  It's for the convenience of using this structure .

The specific difference is :
if struct node{ } If you define the structure in this way . In defining node Structure variable of , It needs to be written like this :struct node n;

If use typedef, It can be written like this :typedef struct node{}NODE; . You can write this when applying for variables :NODE n; It's the same thing as NODE yes node Another name for . The difference is that when used , Can you omit struct This keyword .

.
.
.
.

Example
If you use typedef Words , Will make a difference :

struct Student
{
   int no;
   char name[12];
}stu1;//stu1 Is a global variable created 

typedef struct Student2
{
   int no;
   char name[12];
}stu2;//stu2 It's a structural type , namely stu2 yes Student2 Another name for 

You can directly access stu1.no
however stu2 You must first define stu2 s2;
then s2.no=10;

原网站

版权声明
本文为[Python's path to immortality]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202132041411278.html