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版)
46
|
第
3
章
3.3 字符常量
字符常量(
character constant
)由使用单引号包含的一个或多个字符组成。下面是一些
字符常量的例子:
'a' 'XY' '0' '*'
源代码字符集中的所有字符,均可成为字符常量,除了单引号(
'
)
、反斜线(
\
)
和换
行符。为表示这些字符,必须使用转义字符:
'\'' '\\' '\n'
在第
5
个编译阶段(请参见
1.7
节),字符常量中的字符和转义序列,会被转换成运行字
符集中的对应字符。字符常量中允许的所有转义序列在
3.3.2
节中会详细介绍。
宽字符常量(
wide-character constant
)是以前缀
L
、
u
或
U
定义的字符常量。它们与没有前
缀的字符常量相比,具有不同的类型和值。
3.3.1 字符常量的类型和值
对于不是宽字符的字符常量,其类型为
int
。如果一个字符常量由一个可以在运行字
符集中的用单字节表示的字符组成,其值就是该字符的字符码。例如,在
ASCII
或
ISO 8859-1
中,常量
'a'
的编码是十进制值
97
。在其他所有情况下,特别要注意,如果
一个字符常量包括了超过一个以上的字符,该字符常量的值在不同的编译器中可能会不
同。
下面的程序代码片段测试读进来的字符是否是介于
1
与
5
之间的数字:
#include <stdio.h>
int c =0;
/*
…
*/
c = getchar(); //
读取一个字符
if ( c != EOF && c >'0' && c <'6' ) //
将输入字符与字符常量比较
{
/*
如果输入的字符是介于 ...
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

数据库系统内幕

数据库系统内幕

Alex Petrov
精通機器學習

精通機器學習

Aurélien Géron
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
算法精讲视频课程:24篇系列讲座

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

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

Publisher Resources

ISBN: 9787111562207