我正在传递函数:
fillArrays(arrays);
现在,arrays 是一个二维数组。我这样声明数组:
int **arrays = new int*[NUM_OF_ARRAYS];
arrays[0] = new int[128];
arrays[1] = new int[512];
arrays[2] = new int[2048];
arrays[3] = new int[8192];
arrays[4] = new int[32768];
arrays[5] = new int[131072];
arrays[6] = new int[524288];
arrays[7] = new int[2097152];
我是否正确地将数组传递给以下函数?
void fillArrays(int **arrays) {
const int NUM_OF_ARRAYS = 8;
for(int i = 0;i < NUM_OF_ARRAYS;i++) {
switch(i) {
case 0:
for(int j = 0;j < 128;j++)
arrays[i][j] = 1 + rand() % 2000;
break;
case 1:
for(int j = 0;j < 512;j++)
arrays[i][j] = 1 + rand() % 5000;
break;
case 2:
for(int j = 0;j < 2048;j++)
arrays[i][j] = 1 + rand() % 10000;
break;
case 3:
for(int j = 0;j< 8192;j++)
arrays[i][j] = 1 + rand() % 30000;
break;
case 4:
for(int j = 0;j < 32768;j++)
arrays[i][j] = 1 + rand() % 100000;
break;
case 5:
for(int j = 0;j < 131072;j++)
arrays[i][j] = 1 + rand() % 200000;
break;
case 6:
for(int j = 0;j < 524288;j++)
arrays[i][j] = 1 + rand() % 1000000;
break;
case 7:
for(int j = 0;j < 2097152;j++)
arrays[i][j] = 1 + rand() % 30000000;
break;
}
}
}
如果您需要任何进一步的信息,请告诉我,谢谢!