I\'m translating some MATLAB code into C and the script I\'m converting makes heavy use of 3D arrays with 10*100*300 complex entries. The size of the array also depends on t
Are you sure you need to use malloc
? C allows creating of multidimentional arrays natively:
int a2[57][13][7];
Or you can use malloc
in the following way:
int (*a)[13][7]; // imitates 3d array with unset 3rd dimension
// actually it is a pointer to 2d arrays
a = malloc(57 * sizeof *a); // allocates 57 rows
a[35][7][3] = 12; // accessing element is conventional
free(a); // freeing memory