gpt4 book ai didi

c - 为什么我们不能在一开始就定义指向 null 的结构指针

转载 作者:行者123 更新时间:2023-12-04 12:16:47 24 4
gpt4 key购买 nike

<分区>

为什么我们不能一开始就定义一个指向null的结构指针。我总是必须在我的程序中声明一个指向 null 的结构指针。

在开始时将它们指向 null 不是很麻烦吗?为什么最后会导致一些错误?

struct qwe
{
int data;
struct qwe *next=NULL;
};

或者这样

struct qwe
{
int data;
struct qwe *next;
next=NULL;
};

我正在使用 C 语言,当我这样做时出现错误;

verify.c:8:22: 错误:应为 ';'在声明列表的末尾 结构节点 *next=NULL;

这些是错误

jharvard@appliance (~): make verify
clang -ggdb3 -O0 -std=c99 -Wall -Werror verify.c -lcs50 -lm -o verify
verify.c:9:5: error: type name requires a specifier or qualifier
next=NULL;

verify.c:9:5: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
next=NULL;

verify.c:9:5: error: duplicate member 'next'

verify.c:8:18: note: previous declaration is here
struct node *next;
^
verify.c:9:9: error: expected ';' at end of declaration list
next=NULL;

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