以非零状态(repl.it)C 退出
Exited with non-zero status (repl.it) C++?
我制作了一些代码,以了解链接列表在C 中的工作方式,并且在程序终止之前,它说"以非零状态退出"。我目前正在使用在线编译器REPL.it测试C 代码,我不确定此问题是否相关。我如何解决它?这是我的代码。详细信息详细信息详细信息详细信息详细信息详细信息详细信息详细信息详细信息详细信息详细信息详细信息详细信息
#include <iostream>
#include <string>
using namespace std;
struct node{
int data;
node* next;
};
int main()
{
node* n; //new
node* t; //temp
node* h; //header
n=new node;
n->data=1;
t=n;
h=n;
cout <<"Pass 1"<<endl;
cout <<"t=" << t << endl;
cout <<"n=" << t << endl;
cout <<"h=" << h << endl;
cout << n->data << endl;
n=new node;
n->data=2;
t->next=n;
t=t->next;
cout <<"Pass 2"<<endl;
cout <<"t=" << t << endl;
cout <<"n=" << t << endl;
cout <<"h=" << h << endl;
cout << n->data << endl;
n=new node;
n->data=3;
t->next=n;
t=t->next;
cout <<"Pass 3"<<endl;
cout <<"t=" << t << endl;
cout <<"n=" << t << endl;
cout <<"h=" << h << endl;
cout << n->data << endl;
//Test pass
//exits with non-zero status
//NULL to pointer means invalid address; termination of program?
n=new node;
t=t->next;
n->data=4;
t->next=n;
n->next=NULL;
cout <<"Pass 4"<<endl;
cout <<"t=" << t << endl;
cout <<"n=" << t << endl;
cout <<"h=" << h << endl;
string a;
a="End test";
cout << a << endl;
return 0;
}
输出为
Pass 1
t=0x12efc20
n=0x12efc20
h=0x12efc20
1
Pass 2
t=0x12f0050
n=0x12f0050
h=0x12efc20
2
Pass 3
t=0x12f0070
n=0x12f0070
h=0x12efc20
3
exited with non-zero status
n=new node;
t=t->next; <- error there
n->data=4;
t->next=n;
n->next=NULL;
此时t
是您创建的第三个节点,此时该节点没有值为next
属性。
您可以将调试器用作GDB,以更轻松地查看此类问题(但也许在您的在线编译器中,您不能)
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 如何让LLDB在成功时退出,在失败时等待
- C++控制台应用程序阻止退出
- 程序在执行程序的其余部分之前退出
- 构造函数在退出函数时无法初始化一个参数
- 为什么异常不退出程序?
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 退出简单while循环时出现问题
- 使用vscode调试时,GDB意外退出
- 为什么我会" void value not ignored as it ought to be"?
- pclose() 不会给我进程退出代码
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++从另一个函数退出函数
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- C++逗号分隔的输入数组代码过早退出
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 为什么 C++ 中的以下结构声明会导致退出 127?
- 以非零状态(repl.it)C 退出