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)
|