Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
542 B
9
Indexable
Never
#include<stdlib.h>
#include"function.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);
    free(*arr);
    free(arr);
}