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

  • Home
  • SEARCH
  • 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
I'm just trying to get a general idea of what views are used for
I'm trying to get a better grasp of the inner workings of background jobs
Just trying to grasp the MVC by doing ... and still not sure got
Just trying to get my head around Generics by reading this enlightening article by
Just trying to get my irb sessions to actually list the current line of
Just trying to get up to speed with the SDK... So, I've created my
Just trying to get my head round Spring and figuring out how I wire
I'm just trying to time a piece of code. The pseudocode looks like: start
Developing a website and just trying to get back into the swing of (clever)

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.