在main函数中我们通常使用return (0);这样的方式返回一个值。
exit()通常是用在子程序中用来终结程序用的,使用后程序自动结束跳会操作系统。
但在如果把exit用在main内的时候无论main是否定义成void返回的值都是有效的,并且exit不需要考虑类型,exit(1)等价于return (1).
#include < iostream>
#include < string>
using namespace std;
int main()
{
exit (1); //等价于return (1);
}
exit()通常是用在子程序中用来终结程序用的,使用后程序自动结束跳会操作系统。
但在如果把exit用在main内的时候无论main是否定义成void返回的值都是有效的,并且exit不需要考虑类型,exit(1)等价于return (1).
#include < iostream>
#include < string>
using namespace std;
int main()
{
exit (1); //等价于return (1);
}