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版)
指针
|
151
指针
用该函数。函数通过两个不同的受限指针获得对象,但是由于两个指针参数声明中有关
键字
const
,函数不能修改其内容。
9.4 数组的指针和指针的数组
在许多
C
程序中,指针常被用于引用数组,或者作为数组的元素。指向数组的指针常
被简称为数组指针(
array pointer
),而具有指针类型元素的数组则被称为指针数组
(
pointer array
)。
9.4.1 数组指针
为了便于举例,下面的描述均以一个
int
数组为例。同样的原理可以应用于其他类型数
组,包括多维数组。
要声明指向数组类型的指针,必须使用括号,如下所示:
int (* arrPtr)[10] = NULL; //
一个指针,它指向一个有
10
个
int
元素的数组
如果没有括号,则声明
int * arrPtr[l0];
表示
arrPtr
是
一个具有
10
个
int
类型指针的
数组。下一节会介绍指针的数组。
在该例中,指向有
10
个
int
元素的数组的指针会被初始化为
NULL
。然而,如果把合适数
组的地址分配给它,那么表达式
*arrPtr
会获得数组,并且
(*arrPtr)[i]
会获得索引值
为
i
的数组元素。根据下标运算符的规则,表达式
(*arrPtr)[i]
等同于
*((*arrPtr)+i)
(请参见
5.2.7
节)。因此,
**arrPtr
获得数
组的第一个元素,其索引值为
0
。
为了展示数组指针
arrPtr
的几个运算,下例使用它来定位一个二维数组的某些元素,也
就是矩阵内的某些行(请参见
8.5.1
节):
int matrix[3][10];
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