exit和return

Terminate calling process
Terminates the process normally, performing the regular cleanup for terminating programs.

Normal program termination performs the following (in the same order):
  • Objects associated with the current thread with thread storage duration are destroyed (C++11 only).
  • Objects with static storage duration are destroyed (C++) and functions registered with atexit are called.
  • All C streams (open with functions in <cstdio>) are closed (and flushed, if buffered), and all files created with tmpfile are removed.
  • Control is returned to the host environment.

Note that objects with automatic storage are not destroyed by calling  exit (C++).

If  status is zero or  EXIT_SUCCESS, a  successful termination status is returned to the host environment.
If  status is  EXIT_FAILURE, an  unsuccessful termination status is returned to the host environment.

Otherwise, the status returned depends on the system and library implementation.


exit()和return的区别:
按照ANSI C,在最初调用的main()中使用return和exit()的效果相同。
但要注意这里所说的是“最初调用”。如果main()在一个递归程序中,exit()仍然会终止程序;但return将
控制权移交给递归的前一级,直到最初的那一级,此时return才会终止程序。return和exit()的另一个区别
在于,即使在除main()之外的函数中调用exit(),它也将终止程序。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值