2D-:
cell *(*p_cell)[height][width] = malloc(sizeof(*p_cell));
p_cell - cell. i, j :
cell *p = (*p_cell)[i][j];
, p_cell :
cell *(*p_cell)[][width] = malloc(height * sizeof(*p_cell));
i, j
cell *p = p_cell[i][j];
, cell cell.
2D- , width height , 2D- :
cell *p_cell[height][width];
width height , . , .
Question: Do you really need an element type as a pointer to cell? . This is only useful if you want some of these pointers to point to the same object or have a null value, or point to objects cellthat are referenced elsewhere. Otherwise, it would be much easier to use an array of objects cell, local or functional, or allocated with malloc()or calloc():
cell p_cell[][width] = calloc(sizeof(*p_cell), height);
source
share