//一維-->連續
int *D_array = new int[Length_1D];
delete []D_array;
//二維(兩維長度均動態)-->非連續
int** Array_2D = new int *[Length_2D];
for(int i = 0; i < Length_2D; i++) { Array_2D[i] = new int[Length_1D];
}
xxx
xxx
for(int i = 0; i < Length_2D; i++) { delete []Array_2D[i];
}
delete[] Array_2D;
//二維(兩維長度均動態)-->連續
void **a = (void**)new char[h * sizeof(void*) + w * h * sizeof(int)];
for(int i = 0; i < h; i++) {
a[i] = ((int*)(a + h)) + i * w * sizeof(int);
}
xxx
xxx
delete[] ((void*)a);//二維(一維為固定長度)-->連續int (*Array_2D)[yyy] = new int[Length_2D][yyy]; //yyy->一維固定的長度
xxx
xxx
delete[] Array_2D;
沒有留言:
張貼留言