当前位置:网站首页>Exit() function, macro exit_ Success, macro exit_ Difference between failure, exit() and return

Exit() function, macro exit_ Success, macro exit_ Difference between failure, exit() and return

2022-06-21 14:31:00 Modest learning and progress

exit() Function closes all open files and terminates the program .

exit() The parameters of the function will be passed to some operating systems , The usual convention is that normally terminated programs pass values 0, An abnormally terminated program passes an exception 0 value . Different exit values may be used to identify different causes of program failure ,ANSIC The standard requires the use of values 0 Or macro EXIT_SUCCESS To indicate that the program terminated successfully , Use macros EXIT_FAILURE Indicates that the program aborted unsuccessfully .( The macro and exit() Prototype stay stdlib.h You can find it in the header file EXIT_SUCCESS EXIT_FAILURE)

according to ANSIC, In the initial call main Use and call... In functions exit() The effect is the same , stay main() We use the statement

return 0;

exit(0);

The function of the two statements is the same

Be careful If main() In a recursive program ,exit The function will still terminate the program , however return Hand over control to the recursive upper level , Up to the first level , here return Will terminate the program . return and exit Another difference is , And make in addition main In addition to functions exit() It also terminates the program

 

https://blog.csdn.net/qq_42279940/article/details/82430608

原网站

版权声明
本文为[Modest learning and progress]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202221424252354.html