为什么我们要使用 exit(1) 来异常终止程序?为什么我们要异常终止?
//Program exits itself
//Note that the example would terminate anyway
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout<<"Program will exit";
exit(1); // Returns 1 to the operating system
cout<<"Never executed";
}
最佳答案
我想我看到了问题所在。说 exit(1)
异常终止程序并不是一个非常准确的说法,并且可能会导致困惑。更好的说法是,exit(1)
指示不成功终止,即,它让程序的用户知道出了问题。这只是沟通问题的一种方式。
我实际上并不认为这是一个糟糕的问题,它只是表明了编码新手的困惑。
关于c - 为什么我们明明知道 exit(1) 会异常终止程序,却要把它放在 C 代码中呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43403313/