直接用如下代码说明:
方式一:
typedef struct {
int size;
int** map;
}Map;
Map* initMap(int size) {
Map* m = (Map *)malloc(sizeof(Map));
m->size = size;
m->map = (int** )calloc(sizeof(int** ), m->size);
return m;
}
方式一只是写的常规方法,主要是下边的方式二,感觉很新奇,记录下来。
方式二:
typedef struct {
int size;
int* map[0];
}Map;
Map* initMap(int size) {
Map* m = (Map *)malloc(sizeof(Map)+
sizeof(int* )*size);
m->size = size;
memset(&map[0], 0, sizeof(int* )*size);
return m;
}