gpt4 book ai didi

c - 为什么我的程序直接崩溃了

转载 作者:行者123 更新时间:2023-11-30 20:03:33 25 4
gpt4 key购买 nike

typedef int score;
typedef struct tnode *ptrtonode;
typedef ptrtonode tree;
struct tnode{
score s;
tree next;
bool know;
};

scanf("%d",&n);
tree t[n];

for(i=0;i<n;i++){
scanf("%d",&x);
t[i]->s=x;
t[i]->next=NULL;
t[i]->know=false;
}

这是一个代码片段。

当运行“t[i]->s=x;”时,该程序将崩溃。

我不知道为什么。

最佳答案

tree 的类型为 struct tnode *tree t[n];t 声明为指向 struct tnoden 指针数组(struct t节点*)。在访问这些指针指向的内存之前,您需要为它们分配内存。

关于c - 为什么我的程序直接崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49465454/

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