title: C++ char* problems
body: <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main()
  {
      char *name="Siva",*str;
      for(int i=0;i&lt;strlen(name);i++)
      {
          str[i]=name[i];
      }
      cout&lt;&lt;str;
      return 0;
  }
  </code></pre>
  
  <p>The first program gives output Sivaœ> i.e siva with some garbage values....
  But the second program show segmentation fault...Please help me to find out
  exact answer...</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int main()
  {
      int i=0;
      char *name="Siva",*str;
      for(i=0;i&lt;strlen(name);i++)
      {
          str[i]=name[i];
      }
      cout&lt;&lt;str;
      return 0;
  }
  </code></pre>