数组的地址 [英] Address of array
问题描述
int t[10];
int * u = t;
cout << t << " " << &t << endl;
cout << u << " " << &u << endl;
输出:
0045FB88 0045FB88
0045FB88 0045FB7C
为 U
输出是有道理的。
据我所知, T
和&amp; T公司[0]
应具有相同的价值,但怎么来的&amp; T公司
也是一样的吗? &是什么放大器;?吨实际上意味着
I understand that t
and &t[0]
should have the same value, but how come &t
is also the same? What does &t actually mean?
推荐答案
在 T
在EX pression用于自身,一个数组用于─指针转换发生,这将产生一个指针数组的第一元素
When t
is used on its own in the expression, an array-to-pointer conversion takes place, this produces a pointer to the first element of the array.
在 T
被用作&放大器的参数;
运营商,没有这样的转换发生。在&安培;
则明确采取 T
的地址(阵列)。 &放大器;:T
是一个指向数组作为一个整体
When t
is used as the argument of the &
operator, no such conversion takes place. The &
then explicitly takes the address of t
(the array). &t
is a pointer to the array as a whole.
阵列的第一个元素是在存储器中的相同位置的整个阵列的开始,所以这两个指针的值相同。
The first element of the array is at the same position in memory as the start of the whole array, and so these two pointers have the same value.
这篇关于数组的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!