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

在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);
  }
  

posted @ 2016-06-21 20:00  飘然离去  阅读(222)  评论(0编辑  收藏  举报