**在**中意味着什么

num*_*l25 31 c c++ syntax pointers operators

当一个物体在开头有2个星号时是什么意思?

**variable
Run Code Online (Sandbox Code Playgroud)

Ada*_*eld 47

在声明中,它意味着它是指向指针的指针:

int **x;  // declare x as a pointer to a pointer to an int
Run Code Online (Sandbox Code Playgroud)

使用它时,它会两次使用它:

int x = 1;
int *y = &x;  // declare y as a pointer to x
int **z = &y;  // declare z as a pointer to y
**z = 2;  // sets the thing pointed to (the thing pointed to by z) to 2
          // i.e., sets x to 2
Run Code Online (Sandbox Code Playgroud)

  • @num它会改变y指向内存位置2,并且`*y = 1;`或`**z = 1;`都会尝试更改地址2处的内存,这几乎肯定在法律范围之外你被分配了 (3认同)

Inc*_*ito 29

它是指向指针的指针.有关更多详细信息,您可以检查:指向指针

编辑例如,动态分配多维数组可能很好:

喜欢 :

#include <stdlib.h>

int **array;
array = malloc(nrows * sizeof(int *));
if(array == NULL)
{
    fprintf(stderr, "out of memory\n");
    exit or return
}
for(i = 0; i < nrows; i++)
{
    array[i] = malloc(ncolumns * sizeof(int));
    if(array[i] == NULL)
    {
        fprintf(stderr, "out of memory\n");
        exit or return
    }
}
Run Code Online (Sandbox Code Playgroud)


SLa*_*aks 6

这意味着变量是指向指针的指针.


Mav*_*rik 6

声明变量时指针指针.

在声明之外使用时,双指针取消引用.