由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 关于数组
相关主题
请问关于overloading <<Why do I need to use "plain" pointer?
请教 C++的一个困惑 (operator delete)[合集] question about a static pointer in a member function
0 < -1 ? A c++ questionis smart_ptr really that good?
C++里get array size的问题 (转载)pointer overflow
问题Question about data member offset
C++ formatted output questionC++ Q05: pointer to constant variable
面试问题Why this is a dangling pointer
member and friendC++ Q93 - Q95 (转载)
相关话题的讨论汇总
话题: pointer话题: cout话题: element话题: array话题: sizeof
进入Programming版参与讨论
1 (共1页)
d****n
发帖数: 130
1
int a[] = {3, 2};
cout << *(a+1) << endl;
cout << *(&a+1);
&a应该是变量a的地址吧?a和&a应该不是一回事吧?
n******t
发帖数: 4406
2
In C/C++, the name of a array in an expression decays to a pointer
to its first element EXCEPT it is the operand of & or sizeof.

【在 d****n 的大作中提到】
: int a[] = {3, 2};
: cout << *(a+1) << endl;
: cout << *(&a+1);
: &a应该是变量a的地址吧?a和&a应该不是一回事吧?

l*****d
发帖数: 359
3
如果a是数组, a就是&a吧,一回事儿。

【在 d****n 的大作中提到】
: int a[] = {3, 2};
: cout << *(a+1) << endl;
: cout << *(&a+1);
: &a应该是变量a的地址吧?a和&a应该不是一回事吧?

f**y
发帖数: 138
4
Here a and &a are both pointers and have the same value.
But a + 1 and &a + 1 are different. a is a simple pointer, &a is pointer of
pointer.
a + 1 points to the next element in the array.
&a + 1 points to the address after a, so &a + 1 == (void *)a + sizeof(a)
l*****d
发帖数: 359
5
it seems that a is a pointer to an element, while &a is a pointer to an
array of elements

of

【在 f**y 的大作中提到】
: Here a and &a are both pointers and have the same value.
: But a + 1 and &a + 1 are different. a is a simple pointer, &a is pointer of
: pointer.
: a + 1 points to the next element in the array.
: &a + 1 points to the address after a, so &a + 1 == (void *)a + sizeof(a)

1 (共1页)
进入Programming版参与讨论
相关主题
C++ Q93 - Q95 (转载)问题
int F::*x = &F::x是什么意思?C++ formatted output question
菜鸟请教smart pointer面试问题
c++ 里用到pointer 的地方我们尽可能用smart pointer吗?member and friend
请问关于overloading <<Why do I need to use "plain" pointer?
请教 C++的一个困惑 (operator delete)[合集] question about a static pointer in a member function
0 < -1 ? A c++ questionis smart_ptr really that good?
C++里get array size的问题 (转载)pointer overflow
相关话题的讨论汇总
话题: pointer话题: cout话题: element话题: array话题: sizeof