gpt4 book ai didi

c - : "typedef struct{...} VNode,AdjList[20]"是什么意思

转载 作者:太空狗 更新时间:2023-10-29 15:23:58 26 4
gpt4 key购买 nike

我是 C 初学者,正在学习 Graph 的一些数据结构。今天在维基百科上看了一段C代码:

    #define MAX_VERTEX_NUM 20
typedef struct ArcNode
{
int adjvex; /* Position of Arc's Vertex */
struct ArcNode *nextarc; /* Pointer to next Arc */
InfoType *info; /* Weight) */
}ArcNode; /* Node */
typedef struct
{
VertexType data; /* Vertex Information */
ArcNode *firstarc; /* Location to the first list node */
}VNode,AdjList[MAX_VERTEX_NUM]; /* Head Node */
typedef struct
{
AdjList vertices;
int vexnum,arcnum; /* Vertex count and Arc count */
GraphKind kind; /* type of Garph, directed, undirected..*/
}ALGraph;`

我在这里阅读了几篇相关文章,例如“typedef struct vs struct definitions”,但我对这种用法仍然有点困惑:

typedef struct  {....  }VNode,AdjList[MAX_VERTEX_NUM];

那么 AdjList 是什么?它是一个数组?如果是这样,这个语句是什么意思:

AdjList vertices;

谢谢。引用:http://zh.wikipedia.org/wiki/%E9%82%BB%E6%8E%A5%E8%A1%A8

最佳答案

AdjListstruct 中定义的类型的大小为 MAX_VERTEX_NUM 的数组。

C 中的声明有点滑稽。

typedef struct {...} AdjList[MAX_VERTEX_NUM]

应理解为 AdjList 被定义为结构中定义的类型的大小为 MAX_VERTEX_NUM 的数组。这是一个类型,这意味着您可以将变量声明为该类型的实例。

关于c - : "typedef struct{...} VNode,AdjList[20]"是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29721462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com