What's the difference between void* and void**?

前端 未结 6 1536
别跟我提以往
别跟我提以往 2020-12-13 07:31

It\'s the special property that void* can also be assigned a pointer to a pointer and cast back and the original value is received.

I read this line

6条回答
  •  既然无缘
    2020-12-13 08:11

    A void * can hold any pointer. Since there are no actual void objects, a void * is always a pointer to some other type.

    A void ** is a pointer to a pointer to void, or the address of a void *, i.e., the address of a pointer to void. This is an actual type and doesn't have any magic properties.

    But since a void * can hold any pointer, it can also hold, for example, a void **.

    void **f(int x) {
       static void *y;
       static int *iy;
       y = &x;
       iy = &x;
       // return &iy; // not ok
       return &y; // ok
    }
    

提交回复
热议问题