gpt4 book ai didi

c - 在 C 链表中,为什么节点也是指针?

转载 作者:太空狗 更新时间:2023-10-29 16:50:43 25 4
gpt4 key购买 nike

<分区>

当我们尝试实现链表时,我无法理解我们创建节点指针而不是节点结构的原因:

typedef struct node {
int val;
struct node * next;
} node_t;

node_t * head = NULL;
head = malloc(sizeof(node_t));
if (head == NULL) {
return 1;
}

head->val = 1;
head->next = NULL;

这里,为什么要将head等节点声明为结构体的指针,而不是直接结构体>

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