What does it mean when a object has 2 asterisks at the beginning?
**variable
What does it mean when a object has 2 asterisks at the beginning?
**variable
Pointer to a pointer when declaring the variable.
Double pointer de-reference when used outside the declaration.
It is pointer to pointer. For more details you can check : Pointer to pointer
EDIT 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
}
}
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 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*
.
**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
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.
** is a pointer to a pointer. These are sometimes used for arrays of strings.
It is an example of a double pointer. i.e. pointer to pointer. Here address of pointer variable is stored in another pointer variable.
For more, see this tutorial.
its a pointer to pointer,. as in if *x means that it will contain an address of some variable than if i say m=&x than m is shown as int **m