3-Darray

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
590 B
2
Indexable
Never
#include <stdio.h>
#include "function.h"
#include <stdlib.h>

unsigned*** new_3d_array(unsigned n,unsigned m,unsigned k){

    unsigned ***address1 = malloc(n*sizeof(unsigned**));
    unsigned **address2 = malloc(n*m*sizeof(unsigned*));
    unsigned *address3 = malloc(n*m*k*sizeof(unsigned));

    for(int i = 0; i < n; i++){
        address1[i] = address2 + i*m;
    }
    for(int i = 0; i < n*m; i++){
        address2[i] = address3 + i*k;
    }
    return address1;
}

void delete_3d_array(unsigned ***arr){
    free(arr[0][0]);
    free(arr[0]);
    free(arr);
}