I saw in couple of tree codes that a function of tree class has both * and & with node
for example to insert a node in a BST a function is like this
insertnode(node * &t,string value)
{
t = new node; t-> val = value
// code to find right place in BST
}
I wish to know why we pass reference to pointer in general and also in particular to this case . Please also mention if there is any other scenario of this ,Thanks
Instead of posting another question .
Can someone also point out the use of object class ? i mean using instances of object class did it allocate all the memory gone for all sub classes ? i.e int float etc. etc.
Pointers, as any other variables, are passed by value, unless you specify you want to pass it by reference.
In your case, you pass a reference to a pointer because you want to modify the original pointer. Modifying a pointer doesn’t mean changing the value it points to, but changing the address to which it points to.