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版)
140
第9章
指针
指针(
pointer
)是对数据对象或函数的一种引用。指针有多种用途,例如定义“传址调
用”函数,它还可以实现动态数据结构,例如链表和树。
通常,管理大量数据的有效方法不是直接处理数据本身,而是使用指向数据的指针。例
如,如果需要对大量的大型记录进行排序,对指向该记录的指针列表进行排序效率要比
直接对记录排序高得多,因为这样无需在内存中移动数据。类似地,如果需要把大型记
录传入函数,传递指向该记录的指针会比直接传递记录本身更经济,即使函数不需要修
改该记录。
9.1 声明指针
指针代表了一个对象或函数的地址和类型。如果一个对象或函数具有
T
类型,那么指向
它的指针就具有一个衍生出的指向
T
的指针类型(
pointer to
T
)。例如,如果
var
是一个
float
变量,那么表达式
&var
(其值是该
float
变量的地址)属于指向
float
的指针类型,按
照
C
语言表达,就是
float *
类型。指向任何
T
类型的指针也被简称为
T
指针(
T
point
)。
因此,
&var
中地址运算符会生成一个
float
指针。
因为
var
没有在内存中移动位置,所以表达式
&var
是一个常量指针。然而,
C
也允仵使用
指针类型来定义变量。指针变量存储的是另一个对象或函数的地址。我们后面会进一步
讨论指向数组和函数的指针。首先,看看如何声明指向非数组对象的指针,语法如下:
类型
* [
类型限定符列表
]
名称
[=
初始化器
];
在声明中,星号(
*
)表示“指向……的指针”。标识符“名称”被声明为一个对象,
其对象类型为“类型”,也就是“指向‘类型’的指针”。类型限定符为可选择项,可 ...
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