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版)
80
|
第
5
章
复合赋值的操作数可以属于任何类型,只要这些类型对于对应的二元运算符是合法的即
可。唯一额外的限制是,当指针相加和整数相加,指针必须是左边的操作数,因为这种
加法的结果是指针。看下面的例子:
short *sPtr;
/* ... */
sPtr += 2; //
等效于
sPtr = sPtr + 2;
//
或
sPtr = 2 + sPtr;
5.2.3 自增和自减运算符
++
和--标记都可以用作后缀运算符,也可以用作前缀运算符。表
5-8
描述了这两种运算
符的形式。
表5-8:自增和自减运算符
表达式 意义 副作用 表达式的值
后缀
:
自增 将
x
的值增加1
x++
的值
,
是
x
在加1之前的值
x++
(
就像
x
=
x
+1
)
前缀
:
++x
的值
,
是
x
在加1之后的值
++x
后缀
:
自减 将
x
的值减少1
x
--
的值
,
是
x
在减1之前的值
x
--
(
就像
x
=
x
-
1
)
前缀
:
--
x
的值
,
是
x
在减1之后的值
--
x
这些运算符均需要一个可修改的左值作为它们的操作数。更特别的是,这些操作数必须
属于实数算术类型(而不可以是复数类型)或者对象指针类型。表达式“
++x
”与“
--
x
”等效于“(
x
+= 1
)”和“(
x
-
= 1
)”。
下面的示例展示了自增运算符的用法,同时也展示下标运算符
[]
和间接运算符
*
的用法:
char a[10] = "Jim";
int i = 0;
printf( "%c\n", a[i++] ); //
输出:
J
printf( "%c\n", a[++i] ...
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