c++ new delete 动态分配二维数组

代码
1 #include <iostream>
2
3  using namespace std;
4
5 int main(void)
6 {
7 int **p;
8
9 p = new int*[3];
10
11 for (int i = 0; i < 3; i++)
12 p[i] = new int[4];
13
14 for (int i = 0; i < 3; i++) {
15 for (int j = 0; j < 4; j++)
16 p[i][j] = i+j;
17 }
18
19 for (int i = 0; i < 3; i++)
20 delete []p[i];
21
22 delete []p;
23
24 return 0;
25 }
26

 

posted @ 2010-12-18 16:15  普兒  阅读(5626)  评论(0编辑  收藏  举报