Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With:</p> <pre><code>addNode( node *&amp;head, int value) </code></pre> <p>...the type of <code>head</code> is "reference to pointer-to-node".</p> <p>With:</p> <pre><code>addNode(node **head, int value) </code></pre> <p>... the type is "pointer-to-pointer-to-node".</p> <p>A pointer and a reference are <em>not</em> the same thing. A simple way to think of a reference is as a <em>dereferenced pointer</em>.</p> <p>You would need different syntax to call both versions:</p> <pre><code>node* my_node = 0; addNode(my_node, 0); // syntax for first version addNode(&amp;my_node, 0); // syntax for 2nd version </code></pre> <p>There are semantic differences as well. When you pass a pointer, you can pass NULL. When you pass a reference, you can't. This being a function that takes a ref-to-ptr confuses the matter a little, so let's change the problem a bit:</p> <pre><code>void make_string(string&amp; str_ref) { str_ref = "my str"; } void make_string_again(string* str_ptr) { *str_ptr = "my other string"; } </code></pre> <p>These two finctions do the same thing but one takes a <code>string</code> reference while the other takes a <code>string</code> pointer. If you were to do this:</p> <pre><code>string str; make_string(str); // OK make_string_again(&amp;str); // OK - &amp;str is a pointer to a real string make_string_again(0); // Not OK - compiles but will crash when function dereferences the null pointer </code></pre> <p>You can see it becomes difficult (but not impossible) to call <code>make_string</code> with a null pointer. This could help you to implement better functions in the case where you expect that <code>make_string</code> will <em>never</em> be called with an invalid object.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload