What is ** in C++?

后端 未结 11 1262
野性不改
野性不改 2020-12-04 14:24

I\'ve seen some code, as well as some errors generated from my compiler that have a \'**\' token before the variable (eg **variablename unreferenced-- or someth

11条回答
  •  自闭症患者
    2020-12-04 14:52

    ** is not actually only pointer to pointer (as in declaration), but is also the dereference of a dereference (in a statement).

    It is used often in C which does not have the & notation for references, e.g. to update a return value which is a pointer type:

    int alloc_foo(struct foo **foo_ret)
    {
        *foo_ret = malloc(sizeof(struct foo));
        return 1; /* to indicate success; return value in foo_ret */
    }
    

提交回复
热议问题