Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6100151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:21:12+00:00 2026-05-23T13:21:12+00:00

I was just trying to grasp better understanding of pointers to pointers and on

  • 0

I was just trying to grasp better understanding of pointers to pointers and on internet I found an example of Binary search where the developer used pointers to pointers in an insert function.

My question is:

  1. What edge does the below code have over other BST code which uses single pointers?
  2. At the end of insert function, the code uses a recursive method but I don’t understand the syntax of using & in insert(&(*tree)->right, item);.

The insert function looks like this:

 void insert(node ** tree, node * item)  
 {   
   if(!(*tree))  
   {  
        *tree = item;  
        return;  
   }  
   if(item->val<(*tree)->val)  
      insert(&(*tree)->left, item);  
   else if(item->val>(*tree)->val)  
      insert(&(*tree)->right, item);  
}  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:21:13+00:00Added an answer on May 23, 2026 at 1:21 pm

    Because of this line, which assigns tree to item if it is null, i.e., it starts a new tree.

    *tree = item;
    

    If you only took a node* then you would not be able to assign a new value to it that would be visible from outside of the function. This is because the pointer is passed by value, so the insert function would simply be modifying a copy of the original.

    2) at the end of insert function the code uses recursive method but I didnt understadn teh syntax of using “&” insert(&(*tree)->right, item);

    The -> operator has a igher precedence than the & operator does, so it is passing in the address of *tree->right, i.e., the node** next in line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a better grasp on pointers. My class assignment was to
Just trying to get diff to work better for certain kinds of documents. With
Just trying to understand that - I have never used it before. How is
I'm trying to get a better grasp of the inner workings of background jobs
I am just starting with C and trying to grasp the whole idea of
Just trying to grasp the MVC by doing ... and still not sure got
I'm trying to grasp GADTs , and I have looked at the GADTs example
just trying to test for equality in this piece of code, but getting a
Just trying to still get my head around IOC principles. Q1: Static Methods -
Just trying to establish whether prototype can do something like $$('#ID a:last').css('color','#111'); Any ideas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.