What does the void ** declaration mean in C?

I am starting to learn C and read the following code:

public void** list_to_array(List* thiz){
    int size = list_size(thiz);
    void **array = malloc2(sizeof(void *) * size);
    int i=0;
    list_rewind(thiz);
    for(i=0; i<size; i++){
        array[i] = list_next(thiz);
    }
    list_rewind(thiz);
    return array;
}

I do not understand the point void**. Can someone explain this with some examples?

+5
source share
4 answers

void ** is a pointer to a pointer to void (unspecified type). This means that the variable (memory cell) contains the address in the memory cell, which contains the address in another memory cell, and what is stored there is not indicated. In this question, this is a pointer to an array of void * pointers.

Sidenote: a pointer to a void cannot be dereferenced, but void ** can.

void *a[100];
void **aa = a;

Through this you need to be able to do, for example. aa [17] to get the 18th element of array a.

, .

+4

void** void* pointer void pointer, ! C , . , pointer array of pointers.

+1

void * . , , .

C . , :

char str1[10];
char *str2 = str1;

, void, , char .

. . qsort C :

void qsort ( void * base, 
             size_t num, 
             size_t size, 
             int ( * comparator ) 
             ( const void *, const void * ) );

, . , , . . void *, .

. http://forums.fedoraforum.org/showthread.php?t=138213

0

void pointers are used to store the address of any data type. void**means pointer to void pointer. Void pointers are used in the place where we want the function to receive different data types as an argument to the function. Please see the example below.

void func_for_int(void *int_arg)
{
    int *ptr = (int *)int_arg;
    //some code
}

void func_for_char(void *char_arg)
{
    char *ptr = (char *)char_arg;
    //some code
}

int common_func(void * arg, void (*func)(void *arg))
{
    func(arg);
}

int main()
{
    int a = 10;
    char b = 5;

    common_func((void *)&a, func_for_int);
    common_func((void *)&b, func_for_char);

    return 0;
}
0
source

All Articles