Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
102
|
第
6
章
这意味着,如果一个变量没有被声明为
static
或
extern
,那么该变量的存储空间会在语
句块结束之后自动被释放。关于作用域和存储周期的详细讨论,请参见第
11
章。
6.3 循环
使用循环可以多次重复地执行多条语句,这里的“多条语句”称为循环体。在
C
语言
中,可以使用三种循环,分别是:
while
、
do ... while
和
for
。
在这些语句中,循环体被重复执行的次数由循环条件控制,称为控制表达式
(
controlling expression
)。这是一个标量类型的表达式,也就是说,它属于一个算术表
达式或指针表达式。如果控制表达式的值不等于
0
,循环条件为
true
,反之,循环条件
为
false
。
语句
break
和
continue
用于在一次循环还未执行完时,跳转出循环或返回到循环头部。
它们将在
6.5
节介绍。
6.3.1 while循环
只要控制表达式为
true
,
while
循环就会反复地执行语句:
while
(
表达式
)语句
while
表达式是顶部驱动(
top-driven
)的循环:先计算循环条件(也就是控制表达
式)。如果为
true
,就执行循环体,然后再次计算控制表达式。如果控制表达式为
false
,程序调过循环体,而去执行循环体后面的语句。
从语法上讲,循环体只有一条语句组成。如果需要执行多条语句时,可以使用语句块把
它们组合在一起。例
6-1
展示了一个简单的
while
循环,从控制台读入多个浮点数,并把
它们累加。
例
6-1
:一个
while
循环
/*
从键盘输入数字,然后输出它们的平均值
* -------------------------------------- ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207