#include <iostream>
using namespace std;
//动态分配二维数组
// Author:
int main()
{
const int dim = 3;
//动态分配一维数组
//然后将指针转成二维数组的指针
//也就是指向一维数组的指针
int *ptr = new int [dim * dim];
int (*mat) [dim] = (int (*) [dim] ) ptr;
for (int i = 0; i < dim; i++ ) {
for (int j = 0; j < dim; j++ ) {
mat [i] [j] = i * dim + j;
}
}
for ( int i = 0; i < dim; i++ ) {
for ( int j = 0; j < dim; j++ ) {
cout << mat[ i ] [ j ] <<"";
}
cout << endl;
}
//释放内存时只需要操作一开始的一维数组指针就行
delete[ ] ptr;
return 0;
}