指针之间的区别,以指针数组和指针数组 [英] Difference between pointer to pointer array and pointer array
问题描述
什么是 INT之间的不同** P
和为int * P2 [5]
在第一个字母p是一个指向指针数组,我将在稍后确定!
但P2还指向指针数组!!!!为int * P2 [5]
相同 P2 INT [5];
。
因为在这两种情况下,p2为指针!
有什么区别?
INT ** P
这是一个指针的指针的 INT
。因此, P
可能指向一个指针或指针数组。反过来 * P
可能指向一个 INT
或数组 INT
。究竟背后是什么 P
在其类型pssed不前$ P $。
为int * P2 [5]
这是一个数组,长度为5,指针为 INT
。在这里, P2
是一个长度为5。关于毫无疑问的数组。但对于 P2 [I]
?他们可能是指向一个 INT
,或指针数组。再次,该信息是不是在类型$ P $ psent
在这个问题你的状态:
P2
是一个指针。
块引用>这说法是不正确的。
P2
是一个数组,而不是一个指针。在某些情况下,P2
可能的衰减的一个指针,但它本身并不是一个指针。请注意,如果你开始与变量
P2
,那么你可以把它分配给P
这样的:P = P2;
这是一个数组,
P2
,腐烂的指针。在这一点上,你知道,P
指向指针数组来INT
。不过,如果你有一些
P
类型INT **
那么你不知道p
指向数组。它可能不是。换句话说,指针的类型不完全描述它所指向您似乎得到相当困惑的一个数组和指针的区别。它们是不相同的。阵列不是指针。阵列可以衰减到一个指针。一个指针可以在一个阵列点。
也许关键区别在于一个数组总是以相同的变量。另一方面,一个指针可以由在不同的变量的点。另一个明显的区别是,一个数组变量定义存储。另一方面,一个限定一指针变量没有。必须始终指针赋值给其他对象的地址。
What is the different between
int **p
andint *p2[5]
in the first case p is a pointer to pointers to an array that i will define later!, but p2 also point to array of pointers!!!!.int *p2[5]
is the same asint p2[5];
. Because in both cases p2 is pointer !. what is the difference?解决方案int **p
This is a pointer to pointer to
int
. Sop
could point to a single pointer, or an array of pointers. In turn*p
could point to a singleint
, or an array ofint
. Exactly what is behindp
is not expressed in its type.int *p2[5]
This is an array, of length 5, of pointer to
int
. Here,p2
is an array of length 5. No doubt about that. But what aboutp2[i]
? They could be pointers to a singleint
, or pointers to an array. Again, the information is not present in the type.In the question you state:
p2
is a pointer.That statement is not correct.
p2
is an array, and not a pointer. In certain contexts,p2
may decay to a pointer, but it is not in itself a pointer.Note that if you start with the variable
p2
, then you can assign it top
like this:p = p2;
This is an array,
p2
, decaying to a pointer. At this point you know thatp
points to an array of pointer toint
.However, if all you have is some
p
of typeint**
then you do not know thep
points to an array. It might not. In other words, the type of a pointer does not fully describe what it points to.
You seem to be getting quite confused about the difference between an array and a pointer. They are not the same. An array is not a pointer. An array can decay to a pointer. A pointer can point at an array.
Perhaps the key difference is that an array always refers to the same variables. On the other hand, a pointer can be made to point at different variables. Another obvious difference is that an array variable defines storage. On the other hand, a defining a pointer variable does not. You must always assign the pointer to the address of some other object.
这篇关于指针之间的区别,以指针数组和指针数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!