#include <iostream> int main()
{ int d2a[][] = { , , , , , , , , , , , }; //输出 0,1,2,3,4,5,6,7,8,9,10,11
for (size_t i = ; i < ; i++)
{
for (size_t j = ; j < ; j++)
{
std::cout << d2a[i][j] << ",";
}
} //输出 0077FD04,0077FD04,0077FD14,0077FD24
//可见二维数组名是数据首地址,d2a[0],d2a[1],d2a[2]分别是第一行,第二行,第三行的首地址
std::cout << d2a << "," << d2a[] << "," << d2a[] << "," << d2a[] << std::endl; //最直观的顺序输出所有元素的方式
//输出 0,1,2,3,4,5,6,7,8,9,10,11
int* pa = (int*)d2a;
for (size_t i = ; i < ; i++)
{
std::cout << *(pa + i) << ",";
} //最难理解的二维数组名当指针的输出方式
//输出 0,1,2,3,4,5,6,7,8,9,10,11
for (size_t i = ; i < ; i++)
{
std::cout << *(*d2a + i) << ","; //错误方式,虽然二维数组指向数组首地址,但相当于行指针,d2a+0 = d2a[0], d2a+1 = d2a[1],d2a+2=d2a[2]
//std::cout << *(d2a + i) << ","; } //理解了二维数组名的实质后,下面的就容易理解了
char str[] = "ab";
char(*px)[] = &str; (*px)[] = 'a';
(*px)[] = 'b';
(*px)[] = 'c';
}