解引用指针给出一个地址
Dereferencing a pointer gives an address
我有这个代码片段
const int col= 5;const int row= 5;
int a[row][col] = {0};
int (*p)[col] ;
p = a;
并且这些语句打印相同的地址
cout <<p;
cout << endl;
cout << *p;
在我看来,因为 p
指向 5 ints
的数组,取消引用它
应该给出第一个值,但似乎并非如此。
帮助!
since p
points to an array of 5 ints
说得对。
dereferencing it should give the first value
不是,它的类型是"pointer to array";解引用给出 "array",当你用它做任何事情时它会衰减到一个 int*
指针——包括打印它。
如果你有指向 int
的指针
int * p = a;
那么*p
确实会给出第一个数组元素。
我有这个代码片段
const int col= 5;const int row= 5;
int a[row][col] = {0};
int (*p)[col] ;
p = a;
并且这些语句打印相同的地址
cout <<p;
cout << endl;
cout << *p;
在我看来,因为 p
指向 5 ints
的数组,取消引用它
应该给出第一个值,但似乎并非如此。
帮助!
since
p
points to an array of 5ints
说得对。
dereferencing it should give the first value
不是,它的类型是"pointer to array";解引用给出 "array",当你用它做任何事情时它会衰减到一个 int*
指针——包括打印它。
如果你有指向 int
int * p = a;
那么*p
确实会给出第一个数组元素。