I believe you have misunderstood why there is a pointer-to-pointer in the original code. The "Option a" doesn't make any sense, there is no advantage of using pointer-to-pointer just for the sake of it.
The only reason you would use pointer-to-pointer is because you want to change the pointed-to address and return it to the caller.
For example
void func (int** ptr)
{
*ptr = something;
}
func(&my_ptr);
// is the very thing same as
int* func (int* ptr)
{
return something;
}
my_ptr = func(my_ptr);
You can't use the second version and type ptr = something
inside the function, because ptr
is a local variable and will cease to exist once you leave the function. Assigning something to it won't affect the original pointer at the caller's side.
The only advantage of the pointer-to-pointer version is that the returned type can be used for something else, like for example returning an error code.
And that seems to be exactly why the guy in that video used it. His function looks like
bool insert (int value, node** tree);
where the *tree
is assigned to point at another address from inside the function and the bool is used as a status code, when he reaches the end of a tree branch.