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版)
162
|
第
10
章
构对象属于动态存储类型,那么其成员具有不确定的初始值。另一方面,如果结构对象
具有静态存储周期,那么其非指针成员初始值是
0
,其指针成员初始值是空指针(请参
见第
11
章)。
当定义一个结构对象时,如果想显式地初始化它,必须使用初始化列表:该列表放在一
组大括号内,以逗号分隔各初始化器(
initializer
)或者个别结构成员的初始值。初始化
器和成员声明时的顺序有关:第一个初始化器被关联到第一个成员,第二个初始化器被
关联到第二个成员,依此类推。当然,每个初始化器必须具有匹配对应成员的类型(或
者,能隐式地转换为成员类型)。如下所示:
Song_t mySong = { "What It Is",
"Aubrey Haynie; Mark Knopfler",
"Mark Knopfler",
297,
{ 9, 26, 2000 }
};
在该列表中,每个成员都有一个初始化器。因为成员
published
也是结构类型,所以其
初始化器是另一个初始化列表。
可以使指定的初始化器个数少于结构的成员个数。在这种情况下,最后没有对应到初始
化器的成员会被初始化为
0
。
Song_t yourSong = { "El Macho" };
在上述定义之后,除第一个成员以外,
yoursong
的所有其他成员都是
0
。成员中的
char
数组被赋值为空字符串,而成员
published
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