title: c++ Finding the length of a char pointer
body: <p>I'm trying to make a program that reads in a "string" (into a char *) from user input, then using cstring, it gets the length of what the char * is pointing to. From what I understand, char * is a pointer. A reference to a pointer will be redirected to what it is pointing to. In this case, word should point to 4321, and when word gets output, what it is pointing to is what actually gets output. Also, strlen should read up until the \0, which in this case the string should be 4321\0, so why does it segmentation fault?</p>
  
  <p>Desired result:</p>
  
  <pre><code>Enter a string: 4321
  4321
  (length of 4321)
  </code></pre>
  
  <p>Program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  using namespace std;
  
  int main()
  {
      char *word;
      int len;
  
      cout &lt;&lt; "Enter a string: ";
      cin &gt;&gt; word;
  
      len = strlen(word); //why does this cause a segmentation fault?
  
      cout &lt;&lt; word &lt;&lt; endl;
      cout &lt;&lt; len &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>