【发布时间】:2019-10-18 04:08:11
【问题描述】:
我正在研究 C++ 中的数组和指针。
在这段代码中,我无法理解 'int (*c)[3] = a' 中 [3] 的含义。
是来自'int a[2][3]'??
但是有两个数字,2 和 3。
为什么我们不使用 [2]?
请告诉我 (*c) 旁边的数字规则。
#include <iostream>
using namespace std;
int main()
{
int a[2][3] = {{0,1,2}, {3,4,5}};
cout << "\n";
int (*c)[3] = a; // type of a and c: int (*)[3]
cout << "c + 1 = " << c + 1 << "\n";
cout << "\n";
cout << "Distance between c + 1 and a: " <<
reinterpret_cast<uintptr_t>(c+1) - reinterpret_cast<uintptr_t>(a)
<< "\n";
return 0;
}
【问题讨论】: