Tuesday, December 13, 2022

[FIXED] What does '**' mean in C?

Issue

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


Answered By - Incognito
Answer Checked By - Willingham (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.