在main函数中我们通常使用return (0);这样的方式返回一个值。
但这是限定在非void情况下的也就是void main()这样的形式。
exit()通常是用在子程序中用来终结程序用的,使用后程序自动结束跳会操作
系统。
但在如果把exit用在main内的时候无论main是否定义成void返回的值都是有效的,并且exit不需要考虑类型,exit(1)等价于return (1)
//程序作者:管宁 //站点:www.cndev-lab.com //所有稿件均有版权,如要转载,请务必著名出处和作者
#include <iostream> #include <string> using namespace std;
int main() { exit (1);//等价于return (1); }
|