title: Can't figure out the pointer logic in this example
body: <p>I can't figure this out for the life of me. This is a linked list example.</p>
  
  <p>I'm a beginner. I've been looking at this for about an hour and I'm ready to fold and look for assistance. Heh. </p>
  
  <p>So basically the issue is that there is a pointer on one of the functions, and pointers inside the functions, and pointers bloody everywhere and I can't seem to figure out the series of logical steps that are being taken here.</p>
  
  <p>What I did finally figure out is that Entry *newOne is defining a "struct Entry" pointer. I don't really get what is happening in the full statement, or how the different parts are calling values. At all.</p>
  
  <p>More specifics below.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  struct Entry {
      string name, phone;
      Entry *next;
  };
  
  void PrintEntry(Entry *e)
  {
      cout &lt;&lt; e-&gt;name &lt;&lt; " " &lt;&lt; e-&gt;phone &lt;&lt; endl;
  }
  
  Entry *GetNewEntry()
      {       
          Entry *newOne = new Entry;
          cout &lt;&lt; "Enter name (ENTER to quit):";
          string name;
          getline (cin,name);
          if (name == "") return NULL;
          newOne-&gt;name = name;
          cout &lt;&lt; "Enter phone: ";
          string phone;
          getline(cin, phone);
          newOne-&gt;phone = phone;
          newOne-&gt;next = NULL; // no one follows
          return newOne;
      }
  int main () {
      Entry *n = GetNewEntry();
      PrintEntry(n);
      return 0;
  }
  </code></pre>
  
  <ol>
  <li>Entry *newOne = new Entry
  (I don't understand this - isn't new Entry just an address for a struct Entry? and isn't Entry *newOne a pointer? Then isn't this just assigning the value of the pointer to an address... quite lost.</li>
  </ol>
  
  <p>And if newOne is simply an address (which it is after verifying) then why does saying newOne->phone=phone do anything? That doesn't make sense!</p>
  
  <ol start="2">
  <li><p>Entry *GetNewEntry()
  (I don't understand this - at the end of the function an address to the newOne entry is returned - does the * add to this "return" value perhaps)</p></li>
  <li><p>Entry *n = GetNewEntry()
  (With relation to the function having the pointer symbol on it - GetNewEntry either returns the newOne memory address, or the newOne pointer - and Entry *n being a struct Entry pointer would then be set either to that memory address (much like Entry *newOne = new Entry) or it would be set to the pointer to that address... ugh)</p></li>
  <li><p>PrintEntry(n) refers back to PrintEntry(Entry *e)</p></li>
  </ol>
  
  <p>As you can see I'm confused.</p>