Commit d1af6d3 1 parent b5c12a6 commit d1af6d3 Copy full SHA for d1af6d3
File tree 5 files changed +9
-3
lines changed
5 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -290,6 +290,9 @@ <h2 id="main_1">main 函数的返回值</h2>
290
290
< p > < code > return</ code > 表示函数的返回,main 函数返回,即意味着程序的结束。</ p >
291
291
< p > main 函数总是返回一个整数 (< code > int</ code > 类型),用这个整数向操作系统表示程序退出的原因。</ p >
292
292
< p > 如果程序正常执行完毕,正常结束退出,那就请返回 0。</ p >
293
+ < blockquote >
294
+ < p > < img src ="../img/question.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 通常来说有返回类型的函数都需要在所有分支都有 return 语句,但有趣的是,C++ 标准对 main 函数做了特殊的“宽大处理”:在控制流达到 main 函数的结尾时,如果没有遇到 < code > return</ code > 语句,则等价于执行 < code > return 0;</ code > 。所以对于你本来就打算返回 0 的情况,也可以偷懒不写 < code > return</ code > 语句,编译器自动会帮你加上。以及,main 函数必须返回 < code > int</ code > 类型,不能返回 < code > void</ code > 类型。</ p >
295
+ </ blockquote >
293
296
< p > 返回一个不为 0 的整数可以表示程序出现了异常,是因为出错了才退出的,值的多少可以用于表明错误的具体原因。</ p >
294
297
< blockquote >
295
298
< p > < img src ="../img/awesomeface.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 操作系统:我调用了你这个程序的 main 函数,我好奇程序是否正确执行了?让我们约定好:如果你运转正常的话,就返回0表示成功哦!如果有错误的话,就返回一个错误代码,比如返回1表示无权限,2表示找不到文件……之类的。当然,错误代码都是不为0的。</ p >
Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ <h2 id="_1">前言</h2>
248
248
< blockquote >
249
249
< p > < img src ="./img/bulb.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 本书还在持续更新中……要追番的话,可以在 < a href ="https://github.com/parallel101/cppguidebook "> GitHub</ a > 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一峰电子邮件,提醒你小彭老师更新了。</ p >
250
250
</ blockquote >
251
- < p > 更新时间:2024年08月05日 12:24:25 (UTC+08:00)</ p >
251
+ < p > 更新时间:2024年08月14日 11:48:21 (UTC+08:00)</ p >
252
252
< h2 id ="_2 "> 格式约定</ h2 >
253
253
< blockquote >
254
254
< p > < img src ="./img/bulb.png " height ="30px " width ="auto " style ="margin: 0; border: none "/> 用这种颜色字体书写的内容是温馨提示</ p >
Original file line number Diff line number Diff line change @@ -345,7 +345,7 @@ <h2 id="index-_1">前言</h2>
345
345
<blockquote>
346
346
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 本书还在持续更新中……要追番的话,可以在 <a href="https://github.com/parallel101/cppguidebook">GitHub</a> 点一下右上角的 “Watch” 按钮,每当小彭老师提交新 commit,GitHub 会向你发送一峰电子邮件,提醒你小彭老师更新了。</p>
347
347
</blockquote>
348
- <p>更新时间:2024年08月05日 12:24:25 (UTC+08:00)</p>
348
+ <p>更新时间:2024年08月14日 11:48:21 (UTC+08:00)</p>
349
349
<h2 id="index-_2">格式约定</h2>
350
350
<blockquote>
351
351
<p><img src="../img/bulb.png" height="30px" width="auto" style="margin: 0; border: none"/> 用这种颜色字体书写的内容是温馨提示</p>
@@ -543,6 +543,9 @@ <h2 id="hello_world-main_1">main 函数的返回值</h2>
543
543
<p><code>return</code> 表示函数的返回,main 函数返回,即意味着程序的结束。</p>
544
544
<p>main 函数总是返回一个整数 (<code>int</code> 类型),用这个整数向操作系统表示程序退出的原因。</p>
545
545
<p>如果程序正常执行完毕,正常结束退出,那就请返回 0。</p>
546
+ <blockquote>
547
+ <p><img src="../img/question.png" height="30px" width="auto" style="margin: 0; border: none"/> 通常来说有返回类型的函数都需要在所有分支都有 return 语句,但有趣的是,C++ 标准对 main 函数做了特殊的“宽大处理”:在控制流达到 main 函数的结尾时,如果没有遇到 <code>return</code> 语句,则等价于执行 <code>return 0;</code>。所以对于你本来就打算返回 0 的情况,也可以偷懒不写 <code>return</code> 语句,编译器自动会帮你加上。以及,main 函数必须返回 <code>int</code> 类型,不能返回 <code>void</code> 类型。</p>
548
+ </blockquote>
546
549
<p>返回一个不为 0 的整数可以表示程序出现了异常,是因为出错了才退出的,值的多少可以用于表明错误的具体原因。</p>
547
550
<blockquote>
548
551
<p><img src="../img/awesomeface.png" height="30px" width="auto" style="margin: 0; border: none"/> 操作系统:我调用了你这个程序的 main 函数,我好奇程序是否正确执行了?让我们约定好:如果你运转正常的话,就返回0表示成功哦!如果有错误的话,就返回一个错误代码,比如返回1表示无权限,2表示找不到文件……之类的。当然,错误代码都是不为0的。</p>
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments