title: Why are two declared char* variables getting the same address?
body: <p>TL;DR: Why do my char* variables have the same value, even though I input different ones?</p>
  
  <p>Consider this very short program:</p>
  
  <pre><code>char *GetCompleteString ()
  {
      char *completeString;
      std::cout &lt;&lt; "Please enter the complete string.\n";
      std::cin.getline(completeString,100);
      return completeString;
  }
  
  char *GetSubstring ()
  {
      char* substring;
      std::cout &lt;&lt; "Please enter the substring for which to search.\n";
      std::cin.getline(substring,100);
      return substring;
  }
  
  
  //////////////////////////////////////////////////
  int main(int argc, const char * argv[])
  {
      char *complete, *sub;
  
      complete = GetCompleteString();
      sub = GetSubstring();
      //diagnostic
      std::cout &lt;&lt; "Complete is " &lt;&lt; complete &lt;&lt; " and sub is " &lt;&lt; sub;
      //diagnostic
  
      return 0;
  }
  </code></pre>
  
  <p>Now, I enter "foo" for the first string, and "bar" for the second. But the output tells me that both variables are the same.</p>
  
  <p>The Xcode debugger shows that both variables have the same address, so when I assign a value to bar, the previously-entered foo (which lives at the same address) takes the same value. Here's what the debugger pane is showing just before the program exits:</p>
  
  <pre>
  argv      const char **   0x00007fff5fbff928
  argc      int             1
  complete  char *          0x00007fff5fbff928
  *complete char            'b'
  sub       char *          0x00007fff5fbff928
  *sub      char            'b'
  &complete char **         0x00007fff5fbff8e8
  &sub      char **         0x00007fff5fbff8e0</pre>
  
  <p>Why are these two variables being assigned the same address? What am I missing here? (And why are they retaining the same address as argv, which I think is just for interfacing with the CLI?)</p>
  
  <p>And are they even retaining the same addresses? (I added the last two (&amp;) lines to the debugger, myself. And those show different addresses...)</p>