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版)
114
第7章
函数
对于一个
C
程序而言,它所有的命令都包含在函数内。每个函数都会执行特定的任务。
有一个特别的函数,名称为
main()
——该函数是程序启动后,第一个执行的函数。其他
所有函数都是
main()
函数的子函数(或者与之相关联的过程,例如回调函数),并且它
们的函数名称可以自己设定。
每个函数都只能被定义一次。但一个函数可以根据需要被多次的声明和调用。
7.1 函数定义
函数的定义包含一个函数头(
function head
,或称为声明符(
declarator
))和一个函数
块。函数头指定了函数的名称、返回值的类型以及参数的类型和名称(如果有参数的
话)。函数块中的语句明确了该函数要做的事。函数定义的一般格式如下所示:
类型
名称
(
参数声明
)
函数头
{
/*
声明、语句
*/
函数块
}
]
在上述格式的函数头中,“名称”指函数名,而“类型”包含至少一个类型修饰符,用
来定义函数返回值的类型。返回值的类型可以是
void
或者任何对象类型,但不可以是数
组类型。而且,类型部分还可以包含函数修饰符
inline
或
_Noreturn
,以及存储类修饰
符
extern
和
static
。
函数无法返回函数或数组。然而,可以定义一个函数的返回值为指针,并将该指针指向
一个函数或数组。
在上述格式中,“参数声明”是一个以逗号分隔、由函数参数声明组成的列表。如果该
函数没有参数需要传入,则这个列表为空,或者仅有关键字
void
。
函数
|
115
函数
函数类型不仅指定了其返回值的类型,也指定了其所有参数的类型。例
7-1
是一个简单的
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