1

What's the difference between passing node* and node *& into a function? Don't they both pass a memory address? What do you actually pass when you use one over the other?

4
  • 1
    yeah this is pointers-magic eskimo.com/~scs/cclass/int/sx8.html Commented Sep 13, 2014 at 22:28
  • 2
    It's the exact same thing as int vs. int &. Or double vs. double &. Or any other T vs. T &. Commented Sep 13, 2014 at 22:28
  • @chris node* makes a copy of the address and node*& doesn't? that's it? Commented Sep 13, 2014 at 22:29
  • node *& is similar to node ** Commented Sep 13, 2014 at 22:35

2 Answers 2

2

The node *& is a reference to a pointer, whereas node* is simply a pointer.

In that way, node *& adds an additional level of indirection and it is basically a second name for some node * (pointer to node). It is most frequently used for argument passing.

Please, take a look here for details.

Sign up to request clarification or add additional context in comments.

Comments

2

The node *& notation is a reference to a pointer to a node object, allowing you to change the memory address pointed to by the pointer (through the ref) as well as the node value (through the pointer). Using node * notation only allows you to achieve the latter.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.