1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 int r; //行数
7 int c; //列数
8 cout<<"Please input the number of rows of the dynamic array: ";
9 cin>>r; //输入行数
10 cout<<"Please input the number of columns of the dynamic array: ";
11 cin>>c; //输入列数
12 //创建二维动态数组
13 int **p=new int*[r];
14 for(int i=0;i<r;i++)
15 {
16 p[i]=new int[r];
17 }
18 cout<<"The array named p["<<r<<"]["<<c<<"] is created."<<endl;
19 //循环赋值
20 int temp;
21 for(int i=0;i<r;i++)
22 {
23 for(int j=0;j<c;j++)
24 {
25 cout<<"Please input a value of p["<<i<<"]["<<j<<"] in the array: ";
26 cin>>temp;
27 *(*(p+i)+j)=temp; //寻址赋值
28 }
29 }
30 //循环显示
31 cout<<"The dynamic array is "<<endl;
32 for(int i=0;i<r;i++)
33 {
34 for(int j=0;j<c;j++)
35 {
36 cout<<*(*(p+i)+j)<<" "; //寻址读取
37 }
38 cout<<endl;
39 }
40
41 return 0;
42 }