问题描述
我想看看下面的代码是什么意思.我想我正在创建一个指向 adjlistnode
结构的指针列表的指针,但我不确定.
I want to check what the following code means. I think I am creating a pointer to a list of pointers to adjlistnode
structures but I'm not sure.
代码如下:
typedef struct adjlistnode {int node; int cost; struct adjlistnode *next;}
**AdjMatrix;
我对 **AdjMatrix
究竟是什么感到困惑.就像我上面说的,我认为它是一个指向 adjlistnode
结构的指针列表的指针,但我不确定.我的假设正确吗?
I'm confused as to what **AdjMatrix
actually is. Like I said above, I think it is a pointer to a list of pointers to adjlistnode
structures but I'm not sure. Am I right in my assumption?
推荐答案
typedef
的规则可以简化为以下概括:如果您在 C 中有任何有效的变量声明(没有存储extern
、static
或 register
等),然后在前面绑一个 typedef
根据变量的类型,将变量名转换为新的类型名.
The rules around a typedef
can be simplified to the following generalization: if you have any valid variable declaration in C (without a storage class such as extern
, static
or register
, etc.), then strapping a typedef
at the front turns the variable name into a new type name, based on the type of the variable.
所以这里没有typedef
:
struct adjlistnode {int node; int cost; struct adjlistnode *next;}
**AdjMatrix;
AdjMatrix
是指向 struct adjlistnode
指针的指针类型的变量.
AdjMatrix
is variable of type pointer to pointer to struct adjlistnode
.
但是在您的帖子中,由于 typedef
,AdjMatrix
是一个名称 对于类型 指向 struct adjlistnode 的指针的指针代码>.
But in your post, because of the typedef
, AdjMatrix
is a name for the type pointer to pointer to struct adjlistnode
.
这篇关于直接从 typedef 结构定义创建指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!