<方法一>
int array[2][2][2]={1,2,3,4,5,6,7,8};
<方法二>
int array[2][2][2]={{1,2,3,4},{5,6,7,8}};
i=0,j=0,k=0
1
i=0,j=0,k=1
2
i=0,j=1,k=0
3
i=0,j=1,k=1
4
i=1,j=0,k=0
5
i=1,j=0,k=1
6
i=1,j=1,k=0
7
i=1,j=1,k=1
8
int*** array = new int**[2];
for(int i=0; i<2; i++){
array[i] = new int*[3];
for(int j=0; j<3; j++){
array[i][j] = new int[4];
}
}
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
for(int k=0; k<4; k++){
array[i][j][k]=i+j+k;
printf("i=%d,j=%d,k=%d = ",i,j,k);
std::cout<<array[i][j][k]<<std::endl;
}
}
}
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
delete[] array[i][j];
}
delete[] array[i];
}
delete[] array;
i=0,j=0,k=0 = 0
i=0,j=0,k=1 = 1
i=0,j=0,k=2 = 2
i=0,j=0,k=3 = 3
i=0,j=1,k=0 = 1
i=0,j=1,k=1 = 2
i=0,j=1,k=2 = 3
i=0,j=1,k=3 = 4
i=0,j=2,k=0 = 2
i=0,j=2,k=1 = 3
i=0,j=2,k=2 = 4
i=0,j=2,k=3 = 5
i=1,j=0,k=0 = 1
i=1,j=0,k=1 = 2
i=1,j=0,k=2 = 3
i=1,j=0,k=3 = 4
i=1,j=1,k=0 = 2
i=1,j=1,k=1 = 3
i=1,j=1,k=2 = 4
i=1,j=1,k=3 = 5
i=1,j=2,k=0 = 3
i=1,j=2,k=1 = 4
i=1,j=2,k=2 = 5
i=1,j=2,k=3 = 6