在 C 中创建指向 Typedef 结构的 Typedef 指针 [英] creating Typedef pointers to Typedef structs in C
本文介绍了在 C 中创建指向 Typedef 结构的 Typedef 指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个关于 C 中 typedef
的问题.
Have a question about typedef
in C.
我已经定义了结构:
typedef struct Node {
int data;
struct Node *nextptr;
} nodes;
我将如何创建 typedef
指向 struct
节点的指针??
How would I create typedef
pointers to struct
Node ??
谢谢!
推荐答案
你可以同时 typedef 它们:
You can typedef them at the same time:
typedef struct Node {
int data;
struct Node *nextptr;
} node, *node_ptr;
这可能很难理解,但这与为什么 C 的声明语法的工作方式有很大关系(即为什么 int* foo, bar;
声明 bar
是一个 int 而不是 int*
This is arguably hard to understand, but it has a lot to do with why C's declaration syntax works the way it does (i.e. why int* foo, bar;
declares bar
to be an int rather than an int*
或者您可以在现有的 typedef 基础上进行构建:
Or you can build on your existing typedef:
typedef struct Node {
int data;
struct Node *nextptr;
} node;
typedef node* node_ptr;
或者你可以从头开始,就像你输入其他任何东西一样:
Or you can do it from scratch, the same way that you'd typedef anything else:
typedef struct Node* node_ptr;
这篇关于在 C 中创建指向 Typedef 结构的 Typedef 指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文