C++ **在C中是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2893129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:25:14  来源:igfitidea点击:

what does ** mean in C

c++csyntaxpointersoperators

提问by numerical25

What does it mean when a object has 2 asterisks at the beginning?

对象开头有两个星号是什么意思?

**variable

采纳答案by Incognito

It is pointer to pointer. For more details you can check : Pointer to pointer

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

EDITIt can be good for example for dynamically allocating multidimensional arrays :

编辑它可以很好地例如动态分配多维数组:

Like :

喜欢 :

#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
    }
}

回答by Adam Rosenfield

In a declaration, it means it's a pointer to a pointer:

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

int **x;  // declare x as a pointer to a pointer to an int

When using it, it deferences it twice:

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

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

回答by Mavrik

Pointer to a pointer when declaring the variable.

声明变量时指向指针的指针。

Double pointer de-reference when used outside the declaration.

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

回答by SLaks

It means that the variable is a pointer to a pointer.

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

回答by mfabish

Pointer to a pointer.

指向指针的指针。

回答by Vimal

You can use cdecl to explain C-types.

您可以使用 cdecl 来解释 C 类型。

There's an online interface here: http://cdecl.org/. Enter "int **x" into the text field and check the result.

这里有一个在线界面:http: //cdecl.org/。在文本字段中输入“int **x”并检查结果。

回答by Pavel Radzivilovsky

**variable is double dereference. If variable is an address of an address, the resulting expression will be the lvalue at the address stored in *variable.

** 变量是双重取消引用。如果变量是地址的地址,则结果表达式将是存储在 *variable 中的地址处的左值。

It can mean different things if it's a part of declaration:

如果它是声明的一部分,它可能意味着不同的事情:

type **variable would mean, on the other hand, a pointer to a pointer, that is, a variable that can hold address of another variable, which is also a pointer, but this time to a variable of type 'type'

另一方面,type **variable 意味着指向指针的指针,即可以保存另一个变量地址的变量,该变量也是一个指针,但这次指向类型为“type”的变量

回答by Achim

It means that the variable is dereferenced twice. Assume you have a pointer to a pointer to char like this:

这意味着该变量被取消引用两次。假设您有一个指向 char 的指针的指针,如下所示:

char** variable = ...;

char** 变量 = ...;

If you want to access the value this pointer is pointing to, you have to dereference it twice:

如果你想访问这个指针指向的值,你必须取消引用它两次:

**variable

**多变的

回答by Achim

It is a pointer to a pointer. You can use this if you want to point to an array, or a const char *(string). Also, in Objective-C with Cocoa this is often used to point to an NSError*.

它是一个指向指针的指针。如果您想指向一个array, 或一个const char *(字符串) ,您可以使用它。此外,在带有 Cocoa 的 Objective-C 中,这通常用于指向NSError*.

回答by HZhang

Pointer to another pointer

指向另一个指针的指针