My functions purpose is to make a 2d array of integers on the heap. After I create the pointer to a whole array I return the pointer to the whole array to a void*. I feel like there is a better return type but I can't seem to get the write syntax.
Please let me know if I can do a better return type rather than just a void*.
void* create_matrix(int x, int y){
int i, j, count;
int(*matrix)[x] = calloc(y, sizeof *matrix); // a pointer to a full array of size x.
//matrix = address of array
//*matrix = address of first element of array; *(matrix + 1) = address of first element of second array
//**matrix = element that exists at the first element of array; *(*(matrix + 1) + 1) = second element of second array = matrix[1][1]
count = 0;
for(i = 0; i < y; i++){
for(j = 0; j < x; j++){
matrix[i][j] = ++count;
}
}
for(i = 0; i < y; i++){
for(j = 0; j < x; j++){
printf("%d\n", matrix[i][j]);
}
}
return matrix;
}