开发者

What does '**' mean in C?

What does it mean when an object has two asteris开发者_StackOverflowks at the beginning?

**variable


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


It is pointer to pointer.

For more details you can check: Pointer to pointer

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


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


Pointer to a pointer when declaring the variable.

Double pointer de-reference when used outside the declaration.


Pointer to a pointer.


You can use cdecl to explain C-types.

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


**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.

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'


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

char** variable = ...;

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

**variable


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*.


Pointer to another pointer


** is a pointer to a pointer. These are sometimes used for arrays of strings.


It's a pointer to pointer.

As in if *x means that it will contain an address of some variable then if i say

m=&x then m is shown as

int **m

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜