Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does '**' mean in C?

What does it mean when an object has two asterisks at the beginning?

**variable 
like image 558
numerical25 Avatar asked May 23 '10 19:05

numerical25


People also ask

What does * symbol mean in C?

*= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to C = C * A. /=

What does * mean in C pointers?

A pointer is a variable that stores the memory address of another variable as its value. A pointer variable points to a data type (like int ) of the same type, and is created with the * operator.

What does * mean before a variable in C?

In computer programming, a dereference operator, also known as an indirection operator, operates on a pointer variable. It returns the location value, or l-value in memory pointed to by the variable's value. In the C programming language, the deference operator is denoted with an asterisk (*).


2 Answers

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 
like image 100
Adam Rosenfield Avatar answered Sep 22 '22 14:09

Adam Rosenfield


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     } } 
like image 24
Incognito Avatar answered Sep 22 '22 14:09

Incognito