C 中的 Typedef,使用 * 这是做什么的?

Typdef in C, using * what does this do?

我以前用过typedef,但我从来没有用过带指针的。这对 typedef 有什么影响?

参考代码:

typedef struct node NODE,  *PNODE, **PPNODE;

单个 typedef 行定义了三个类型别名。第二个和第三个分别是"pointer to node"和"pointer to pointer to node"。

拆分成三个说法可能更容易理解:

typedef struct node NODE;
typedef struct node *PNODE;   // PNODE is pointer to node
typedef struct node **PPNODE; // PPNODE is pointer to pointer to node

它不影响 typedef,它影响类型。

  • PNODE 是指向 struct node
  • 的指针
  • PPNODE 是指向 struct node
  • 的指针

您可以使用 NODE

代替 struct node

您可以将其替换为 PNODE

而不是使用 struct node*

您可以使用 PPNODE

代替 struct node**

语句可以分解为

typedef struct node NODE;
typedef struct node* PNODE;   // PNODE is pointer to node
typedef struct node** PPNODE; // PPNODE is pointer to pointer to node