【发布时间】:2021-08-01 21:36:55
【问题描述】:
假设我有一个数组int a[] = {2, 3, 4};
为什么指向第一个元素&a[0] 的指针可以指向数组元素或一般的值,而指针&a 不能?
cout << (&a[0])[1]; // 3
cout << (&a)[0]; // some weird adress (presumably of the array itself
cout << (&a)[1];
// a higher adress probably the adress after the end of the array so &a + 0xC (length of array) + 0x1
指针本身 (&a)、类型(带有 int (*)...的东西)是否像某种数组?
【问题讨论】:
-
用
struct s { int x, y , z;} b;做同样的实验并比较结果