这个问题建立在先前提出的问题之上: Pass by reference multidimensional array with known size
我一直在试图弄清楚如何让我的函数与 2d 数组引用很好地配合使用。我的代码的简化版本是:
unsigned int ** initialize_BMP_array(int height, int width)
{
unsigned int ** bmparray;
bmparray = (unsigned int **)malloc(height * sizeof(unsigned int *));
for (int i = 0; i < height; i++)
{
bmparray[i] = (unsigned int *)malloc(width * sizeof(unsigned int));
}
for(int i = 0; i < height; i++)
for(int j = 0; j < width; j++)
{
bmparray[i][j] = 0;
}
return bmparray;
}
我不知道如何重写此函数,以便它可以在我通过引用将 bmparray 作为空的 unsigned int ** 传入的地方工作,以便我可以在一个函数中为数组分配空间,并设置值在另一个。