从C中的主要功能返回与退出 [英] Return vs Exit from main function in C

查看:46
本文介绍了从C中的主要功能返回与退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道从主函数返回和退出之间有什么区别.当调用它们中的每一个时,在幕后会发生什么,以及在每种情况下如何返回控件. 如果有人可以深入研究这个主题,我将不胜感激.

Hi I wanted to know what the differences between returning and exiting from the main function are. What happens behind the scenes when each of them are invoked, and how is the control returned in each case. I would really appreaciate it if someone could dive deep into this subject.

推荐答案

没有区别.

在幕后,发生的事情(至少在某些流行的操作系统上是这样):

Behind the scenes, what happens (at least on some popular operating systems) is this:

// Set up argc and argv
int retcode = main(argc, argv);
exit(retcode);

该行为由C标准保证:

...从初始调用返回到main函数等同于使用main函数返回的值作为参数来调用exit函数...(第5.1.2.2.3节) )

... a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument ... (§5.1.2.2.3)

这篇关于从C中的主要功能返回与退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆