C++ new

 1 //#include "stdafx.h"
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 int main() {
 7     int m = 10, n = 5, ** p = new int*[m]; // 10 lines and 5 columns. initial value is not zero. non-contiguous space
 8     int i;
 9     for (i = 0; i < 10; i++) {
10         p[i] = new int[n]; // generate an array of the second dimension
11     }
12     
13     printf("%d
", p[0][0]); // random value
14 
15     for (i = 0; i < 10; i++) {
16         delete[] p[i]; // delete the array of the second dimension
17     }
18     delete[] p; // delete the array of the first dimension
19 
20     system("pause");
21     return 0;
22 }

参考资料

C++中怎么用new定义一个二维数组?

C++二维数组new小结

原文地址:https://www.cnblogs.com/WJQ2017/p/7569547.html