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版)
40
|
第
2
章
2.6 void类型
void
类型修饰符(
type specifier
)表示“没有值可以获得”。因此,不可以采用这个类
型声明变量或常量。
void
类型可以用于下面各小节所描述的目的。
2.6.1 void用于函数声明
没有返回值的函数,其类型为
void
。例如,标准库函数
perror()
被声明为以下原型:
void perror( const char * );
下面是另一个函数原型的声明,参数列表中的关键字
void
表示该函数没有参数:
FILE *tmpfile( void );
如果尝试进行函数调用,例如采用
tmpfile("name.tmp"
),则编译器会报错。如果该函
数声明时参数列表中未采用
void
,则
C
编译器就无法获得关于该函数参数的信息,因
此,无法判断
tmpfile ("name.tmp")
的调用是否正确。
2.6.2 void类型表达式
void
类型表达式指的是没有值的表达式。例如,调用一个没有返回值的函数,就是一种
void
类型表达式:
char filename[] = "memo.txt";
if ( fopen( filename, "r") == NULL )
perror( filename ); // void
表达式
类型转换(
cast
)运算
(void)
表达式显式地将表达式的返回值丢弃,例如,如下代码丢
弃了函数返回值:
(void)printf("I don't need this function's return value!\n")
;
2.6.3
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