#includeusing namespace std; int ROW = 5; int COL = 5; int main() { int **a = new int*[ROW]; for(int i = 0; i < ROW; i++) a[i] = new int[COL]; for(int r = 0; r < ROW; r++) for(int c = 0; c < COL; c++) a[r][c] = 6; for(int i = 0; i < ROW; i++) { for(int j = 0; j < COL; j ++) cout << a[i][j] << " "; cout << endl; } for(int i = 0; i < ROW; i ++) delete[] a[i]; delete[] a; int **b = NULL; b = (int**)malloc(sizeof(int*) * ROW); for(int r = 0; r < ROW; r++) b[r] = (int*)malloc(sizeof(int) * COL); for(int i = 0; i < ROW; i ++) { for(int j = 0; j < COL; j++) { cout << b[i][j] << " "; } cout << endl; } for(int i = 0; i < ROW; i++) delete[] b[i];//这里一定要释放彻底 delete[] b; return 0;
posted on 2013-05-06 12:15 阅读( ...) 评论( ...)