What does ** mean in C?

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**是一个双重值,因为它本质上是对引用的取消引用。我的想法正确吗?如果没有,有人可以解释一下**这个例子中的用法吗?

Jon*_*ood 5

在这种情况下,double表示 double 类型的变量。

double* 表示指向双变量的指针。

double** 表示指向双变量指针的指针。

在您发布的函数的情况下,它用于创建一种二维双精度数组。也就是说,一个指向双指针数组的指针,而这些指针中的每一个都指向一个指针数组。

  • @StenSoft:不,**指针不是数组**。请阅读 [comp.lang.c FAQ](http://www.c-faq.com/) 的第 6 节。我要求您删除您的评论,因为它可能会误导他人。数组是“真正的”指针的想法是一种普遍的误解。请不要帮助传播它。 (5认同)
  • 二维数组是数组的数组;整个事情在内存中是连续的。指向指针的指针可用于实现行为类似的数据结构,每行独立分配,但将其称为二维数组会产生误导。 (3认同)