还是先上代码吧。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//
// 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下查看动态数组的方法

1
2
(uint64_t (*)[10])arr
(uint64_t (**)[10][10])arr2