I created a two-dimensional array in a double pointer int with the following methodology.
int **make2Dint(int rows, int columns) {
int **a = (int **)calloc(rows, sizeof(int *));
if (!a) {
return (int **)NULL;
}
for (int i = 0; i < rows; i++) {
a[i] = (int *) calloc(columns, sizeof(int));
if (!a[i]) {
return (int **)NULL;
}
}
return a;
}
For this, I also wrote a free function that looks like this
void free2DArray(void **a, int rows) {
for (int i = 0; i < rows; i++) {
free(a[i]);
}
free (a);
}
When you are going to use my free function (however free2DArray(array, rows);
, gcc gave me a warning.
In file included from life.c:6:0:
twoD.h:14:6: note: expected ‘void **’ but argument is of type ‘int **’
void free2DArray(void **a, int rows);
^~~~~~~~~~~
Now I can get away with the act in void **
, but this seems to indicate that my use is void **
problematic.
C. void * , ( ) , void *; , void **, , void *. void ** (, * void *, void **), , void * . , , *; .
, void **, , - void *; (void **) dp, , ( , , . 13.9). , void **, void *, , void *, .
, , , . - , ?