title: Character Array of dynamic length
body: <p>I have written a C++ Function which can be represented as below:
  All it does is take a string (this is where it crashes) and reverse it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  int main()
  {
   cout&lt;&lt;"Enter a string: "&lt;&lt;endl;
   char *str;
   gets(str);
   cout&lt;&lt;"Reversed String is: ";
   for(int i=strlen(str)-1;i&gt;=0;i--)
      cout&lt;&lt;(str[i]);
   return 0;
  }
  </code></pre>
  
  <p>I guess there's some kind of memory access violation.</p>
  
  <p>Any clue why this doesn't work? </p>
  
  <p>Error: <strong>Segmentation fault (core dumped)</strong></p>