还是先上代码吧。
//
// Created by ismdeep on 2019-01-28.
//
#ifndef ISMDEEP_ARRAY_H
#define ISMDEEP_ARRAY_H
#include <stdint.h>
void * create_1d_arr(size_t size, size_t sizeof_item) {
void * arr = malloc(sizeof_item * size);
return arr;
}
void ** create_2d_arr(size_t rows, size_t cols, size_t sizeof_item) {
void ** arr = (void **)malloc(sizeof(size_t) * rows);
for (size_t row_id = 0; row_id < rows; ++row_id) {
arr[row_id] = malloc(sizeof_item * cols);
}
return arr;
}
#endif //ISMDEEP_ARRAY_H
另附上CLion下查看动态数组的方法
(uint64_t (*)[10])arr
(uint64_t (**)[10][10])arr2