exit()退出程序,把控制权交给OS 
return结束当前函数,返回函数值,把控制权交给调用函数
在main函数中return 与exit用法差不多,

但return会自动调用对象的析构函数, 而exit不会


复制代码
      
1 #include < iostream > 2 using namespace std; 3 class Temp 4 { 5 public : 6 Temp(){cout << " Constructor! " << endl;} 7 ~ Temp(){cout << " Destructor! " << endl;} 8 }; 9 int main() 10 { 11 Temp t; 12 exit( 0 ) ; 13 }
复制代码

 

     
Constructor ! Press any key to continue

 

 

复制代码
      
1 #include < iostream > 2 using namespace std; 3 class Temp 4 { 5 public : 6 Temp(){cout << " Constructor! " << endl;} 7 ~ Temp(){cout << " Destructor! " << endl;} 8 }; 9 int main() 10 { 11 Temp t; 12 return 0 ; 13 }
复制代码
     
Constructor ! Destructor ! Press any key to continue