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版)
43
第3章
字面量
在
C
语言源代码中,字面量是一种标记,用来描述一个固定的值,可能是整数、浮点
数、字符或者字符串。一个字面量的类型由它的值和记数法(
notation
)决定。
这里所讨论到的字面量,不同于复合字面量(
compound literal
),后者是
C99
标准新增
的。复合字面量是普通可修改对象,类似于变量。第
5
章将会详细讨论复合字面量以及
用于生成它们的特殊运算符。
3.1 整数常量
整数常量(
integer constant
)可以被表示为常见的十进制数字,或者八进制或十六进制
记数法的数字。必须在数字的前面加上前缀以指定所需采用的记数法。
十进制常量(
decimal constant
)起始数字不可为
0
。例如,
255
表示一个基数为
10
的十进
制常量,其值是
255
。
以
0
开始的数字会被解释为八进制常量(
octal constant
)。八进制(也就是基数为
8
)记
数法只使用数字
0~7
。例如,
047
就是一个有效的八进制常量,表示
4
×
8+7
,等价的十进
制常量是
39
。十进制常量
255
等于八进制常量
0377
。
十六进制常量(
hexadecimal constant
)以
0x
或
0X
作为前缀。十六进制数字
A
到
F
可以是大
写或小写。例如,
Oxff
、
OXff
、
0xFF
和
0XFF
都表示同一个十六进制常量,它们都等于十
进制常量
255
。
由于所定义的整数常量最终将用于表达式与声明中,因此它们的类型非常重要。当常量
的值被确定时,常量的类型也会被同时定义。如上述提到的例子,整数常量通常是
int
类型。然而,如果一个类型的常量值在
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