正在阅读:exit()与return()函数的差别exit()与return()函数的差别

2005-03-04 10:17 出处:PConline 作者:管宁 责任编辑:xietaoming

  exit()子程序终止函数与return()函数的差别

  在main函数中我们通常使用return (0);这样的方式返回一个值。

  但这是限定在非void情况下的也就是void main()这样的形式。

  exit()通常是用在子程序中用来终结程序用的,使用后程序自动结束跳会操作系统。

  但在如果把exit用在main内的时候无论main是否定义成void返回的值都是有效的,并且exit不需要考虑类型,exit(1)等价于return (1)

#include <iostream
#include <string
using namespace std; 
 
int main()   

    exit (1);//等价于return (1); 
}

302 Found

302 Found


Powered by Tengine
tengine