C++ difference between ** and *& in parameter passing

前端 未结 3 569
星月不相逢
星月不相逢 2020-12-24 04:43

I have implemented operations on a list, one of them is add, and since i don\'t want to return anything, i read that i had to use **, and it works, but i saw on another plac

3条回答
  •  一向
    一向 (楼主)
    2020-12-24 05:16

    The first (**) is a pointer to a pointer and the second (*&) is a reference to a pointer.

    A reference and a pointer are conceptually quite similar. But there are some important differences, for example:

    • A reference cannot be NULL (but it can refer to a pointer which points to NULL).
    • You can't modify a reference to refer to something else.
    • You need to dereference a pointer to access the value.

    See this related question for more differences:

    • Difference between pointer variable and reference variable in C++

提交回复
热议问题