1. ypedef
1.1: usage of typedef (as shown above)
One-sentence summary of typedef usage —— rename the defined type
For example: the familiar int type defines a variable, such as int a;
Suddenly, I felt that int was a bit long, so I changed int to a single letter Z; such as typedef int Z;
Z a = int a ;
1.2, the code is as follows
#include <stdio.h>
typedef int Z;
int main()
{
int a =10;
printf("a = %d\n",a);
printf("%d\n",sizeof(a));
Z b=10;
printf("b = %d\n", b);
printf("%d\n",sizeof(b));
return 0;
}
operation result
a = 10
4
b = 10
4
2. Application of typedef in structure
#include<stdio.h>
//结构体
typedef struct node
{
int data;
struct node *next;
} * Pnode,Node;
2.1, Pnode analysis
PNode is equivalent to struct node *;
Do we have doubts, there is not a * , it should not be *PNode .
Why not *PNode
Analysis: First of all, we know that typedef is to rename the defined type. such as this structure
changed to red font
typedef struct node
{int data;
struct node *next;
} * Pnode,Node;
Omit the structure content, typedef struct node * Pnode
As for why it is not *PNode, we have not learned the definition type of *PNode from the beginning of learning c language to the end.
That is why it is not *PNode, so it is concluded that PNode is equivalent to struct node *;
2.2, Node analysis
From Section 2.1, we can easily conclude that
Node is equivalent to struct node;