Search code examples
c++csyntaxpointersoperators

What does '**' mean in C and C++?


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

**variable

Solution

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