fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. int dim1=2, dim2=2, dim3=3;
  7. int i,j,k;
  8. int x,y,z;
  9.  
  10. int*** array = (int ***)malloc(dim1*sizeof(int**));
  11.  
  12. for (i = 0; i< dim1; i++) {
  13. array[i] = (int **) malloc(dim2*sizeof(int *));
  14.  
  15. for (j = 0; j < dim2; j++) {
  16. array[i][j] = (int *)malloc(dim3*sizeof(int));
  17. }
  18.  
  19. }
  20.  
  21. for(z = 0; z != dim1; ++z) {
  22. for(y = 0; y != dim2; ++y) {
  23. for(x = 0; x != dim3; ++x){
  24. array[z][y][x] = z + y + x;
  25. }
  26. }
  27. }
  28.  
  29.  
  30. for(z = 0; z != dim1; ++z) {
  31. for(y = 0; y != dim2; ++y) {
  32. for(x = 0; x != dim3; ++x){
  33. printf("%d\n",array[z][y][x]);
  34. }
  35. }
  36. }
  37.  
  38. printf("----\n");
  39.  
  40. int *a_ptr = array[0][0];
  41. //不知為何這樣用
  42.  
  43. for(int q=0;q<12;q++){
  44. printf("%d\n",*(a_ptr+q));
  45. }
  46.  
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
0
1
2
1
2
3
1
2
3
2
3
4
----
0
1
2
0
0
0
33
0
1
2
3
0