Cleaner way to handle double pointer in C++ BST? I have an implementation for my first binary search tree in C++. I was wondering if there was some cleaner way to avoid using the double pointer in the way I have my code setup? Such as on one line I have:

(*node)-&gt;left = insert(&amp;((*node)-&gt;left),value);


Which seems a bit "messy", but it almost seems necessary for the way I have implemented the BST. Maybe I am possibly missing a way I can change the syntax slightly to achieve the same result? I understand that I can have a double pointer as a parameter for my functions, but I have been told that it is not the standard in C++. I have my code posted below, along with how I am testing it.I am trying to prepare for technical interviews so any feedback is welcome. 

#include&lt;stdio.h&gt; 
#include&lt;stdlib.h&gt; 
#include&lt;iostream&gt;
struct Node 
{ 
    int data; 
    Node *left, *right; 
}; 

// A utility function to create a new BST node 
Node* newNode(int data) 
{ 
    Node *temp =  new Node(); 
    temp-&gt;data = data; 
    temp-&gt;left = NULL; 
    temp-&gt;right = NULL; 
    return temp; 
} 

// A utility function to do inorder traversal of BST 
void inorder(Node **root) 
{ 
    if (*root != NULL) 
    { 
        inorder(&amp;((*root)-&gt;left)); 
        printf("%d \n", (*root)-&gt;data); 
        inorder(&amp;((*root)-&gt;right)); 
    } 
} 

/* A utility function to insert a new node with given key in BST */
Node* insert(Node** node, int value) 
{ 
    if(*node==NULL){
        return newNode(value);
    }
    if((*node)-&gt;data &gt; value){
        (*node)-&gt;left = insert(&amp;((*node)-&gt;left),value);
    }
    else if((*node)-&gt;data &lt; value){
        (*node)-&gt;right = insert(&amp;((*node)-&gt;right),value);
    }
    return *node;
} 

// Driver Program to test above functions 
int main() 
{ 
    /* Let us create following BST 
              50 
           /     \ 
          30      70 
         /  \    /  \ 
       20   40  60   80 */
    Node *root = NULL; 
    root = insert(&amp;root, 50); 
    insert(&amp;root, 30); 
    insert(&amp;root, 20); 
    insert(&amp;root, 40); 
    insert(&amp;root, 70); 
    insert(&amp;root, 60); 
    insert(&amp;root, 80); 

    // print inoder traversal of the BST 
    inorder(&amp;root); 

    return 0; 
} 


EDIT: 
By changing " ** " in the parameters of the function to "*&amp;" was able to make code much easier to read, with the same functionality. 

#include&lt;stdio.h&gt; 
#include&lt;stdlib.h&gt; 
#include&lt;iostream&gt;
struct Node 
{ 
    int data; 
    Node *left, *right; 
}; 

// A utility function to create a new BST node 
Node* newNode(int data) 
{ 
    Node *temp =  new Node(); 
    temp-&gt;data = data; 
    temp-&gt;left = NULL; 
    temp-&gt;right = NULL; 
    return temp; 
} 

// A utility function to do inorder traversal of BST 
void inorder(Node *&amp;root) 
{ 
    if (root != NULL) 
    { 
        inorder(((root)-&gt;left)); 
        printf("%d \n", (root)-&gt;data); 
        inorder(((root)-&gt;right)); 
    } 
} 

/* A utility function to insert a new node with given key in BST */
Node* insert(Node*&amp; node, int value) 
{ 
    if(node==NULL){
        return newNode(value);
    }
    if((node)-&gt;data &gt; value){
        node-&gt;left = insert(((node)-&gt;left),value);
    }
    else if((node)-&gt;data &lt; value){
        (node)-&gt;right = insert(((node)-&gt;right),value);
    }
    return node;
} 

// Driver Program to test above functions 
int main() 
{ 
    /* following BST 
              50 
           /     \ 
          30      70 
         /  \    /  \ 
       20   40  60   80 */
    Node *root = NULL; 
    root = insert(root, 50); 
    insert(root, 30); 
    insert(root, 20); 
    insert(root, 40); 
    insert(root, 70); 
    insert(root, 60); 
    insert(root, 80); 

    // print inoder traversal of the BST 
    inorder(root); 

    return 0; 
}
If you're trying to learn C++, you should get comfortable with constructors and destructors — they're what C++ is all about!

struct Node 
{ 
    int data; 
    Node *left, *right; 
}; 

// A utility function to create a new BST node 
Node* newNode(int data) 
{ 
    Node *temp =  new Node(); 
    temp-&gt;data = data; 
    temp-&gt;left = NULL; 
    temp-&gt;right = NULL; 
    return temp; 
}


That's C style. C++ style would be:

struct Node { 
    int data_; 
    Node *left_ = nullptr;
    Node *right_ = nullptr;

    explicit Node(int data) : data_(data) {}
}; 


Then when you want a new heap-allocated node, you don't call newNode(42) — you call new Node(42)! Or, a good habit you should get into: call std::make_unique&lt;Node&gt;(42) to get back a smart pointer.

Notice that I added sigils to your data members (data_ etc) to distinguish them from non-member variables; and I declared no more than one variable per line to reduce reader confusion.



void inorder(Node *&amp;root) 
{ 
    if (root != NULL) 
    { 
        inorder(((root)-&gt;left)); 
        printf("%d \n", (root)-&gt;data); 
        inorder(((root)-&gt;right)); 
    } 
}


Several things weird here. First, you have a bunch of unnecessary parentheses. (root) is the same thing as root. Second, you're passing root by non-const reference, even though you don't intend to modify it. Third, very minor nit, you're using C-style NULL instead of nullptr. Fourth, why do you print a space before the newline? Fixed up:

void inorder(const Node *root)
{
    if (root != nullptr) {
        inorder(root-&gt;left); 
        printf("%d\n", root-&gt;data); 
        inorder(root-&gt;right); 
    } 
}


Remember to remove the redundant parentheses in places like insert(((node)-&gt;right),value). It's much easier to read as insert(node-&gt;right, value).