一个指向二维数组 [英] A pointer to 2d array
问题描述
我有一个关于一个指针二维数组的问题。如果数组是一样的东西。
I have a question about a pointer to 2d array. If an array is something like
int a[2][3];
那么,这是一个指向数组 A
?
int (*p)[3] = a;
如果这是正确的,我想知道什么呢 [3]
从 INT(* P)指[3]
?
If this is correct, I am wondering what does [3]
mean from int(*p)[3]
?
推荐答案
而不是指 INT [2] [3]
为二维数组,你应该考虑到是一个数组的数组。它带有两个项目,每个项目本身就是其与3整型数组的数组。
Rather than referring to int[2][3]
as a '2d array', you should consider in to be an 'array of arrays'. It is an array with two items in it, where each item is itself an array with 3 ints in it.
int (*p)[3] = a;
您可以使用 P
以指向这两个项目的 A
。 P
指向三个int数组,第一个这样的项目。 P + 1
将指向第二个三int数组。要初始化 P
来指向第二个元素
You can use p
to point to either of the two items in a
. p
points to a three-int array, the first such item. p+1
would point to the second three-int array. To initialize p
to point to the second element
int (*p)[3] = &(a[1]);
以下是等效的方式指向所述第一两个项目的
The following are equivalent ways to point to the first of the two items.
int (*p)[3] = a; // as before
int (*p)[3] = &(a[0]);
这篇关于一个指向二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!