I'd /ike to know, how to pass pointers to dynamically allocated arrays using function arguments. This function is supposed to allocate array 10x10 (checks skipped for simplicity sake). Is this possible? What am i doing wrong? Thanks in advance.
int array_allocate2DArray ( int **array, unsigned int size_x, unsigned int size_y)
{
array = malloc (size_x * sizeof(int *));
for (int i = 0; i < size_x; i++)
array[i] = malloc(size_y * sizeof(int));
return 0;
}
int main()
{
int **array;
array_allocate2DArray (*&array, 10, 10);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…