Bri*_*ian 5 c memory pointers reference dereference
I have a sample C program I am trying to understand. Below is a function excerpt from the source code:
double** Make2DDoubleArray(int arraySizeX, int arraySizeY)
{
double** theArray;
theArray = (double**) malloc(arraySizeX*sizeof(double*));
int i = 0;
for (i = 0; i < arraySizeX; i++)
theArray[i] = (double*) malloc(arraySizeY*sizeof(double));
return theArray;
}
Run Code Online (Sandbox Code Playgroud)
My question is what is the significance of the ** in the return type. I know that the * is generally used as a pointer. I know that it may also be used to dereference the pointer.
这让我认为这double**是一个双重值,因为它本质上是对引用的取消引用。我的想法正确吗?如果没有,有人可以解释一下**这个例子中的用法吗?
在这种情况下,double表示 double 类型的变量。
double* 表示指向双变量的指针。
double** 表示指向双变量指针的指针。
在您发布的函数的情况下,它用于创建一种二维双精度数组。也就是说,一个指向双指针数组的指针,而这些指针中的每一个都指向一个指针数组。