title: How do you assign value to char[] in heap?
body: <p>I got a _CrtIsValidHeapPointer error with my code. And I finally find out what caused the trouble.<br>
  I use the example below to illustrate it:  </p>
  
  <pre><code>char* c=(char*)malloc(20*sizeof(char));
  //cout&lt;&lt;&amp;c&lt;&lt;endl;
  c="hello world";
  //cout&lt;&lt;&amp;c&lt;&lt;endl;  //if you uncomment the 2 clauses,you'll see the address is the same
                                    //which means the string literal is in the heap
  cout&lt;&lt;c&lt;&lt;endl;
  free(c);
  </code></pre>
  
  <p>1) It seemed that spaces used by string literals can't be freed? Why?</p>
  
  <p>2)What't the method do you use to assign valee to array of char?<br>
  ps: I use <code>sprintf(c,"hello world");</code> that works fine. But any better way?</p>
  
  <hr>
  
  <p>After read the answers. I realize that I misunderstand the meaning of &amp;c.<br>
  I should use <code>printf("%p\n",c);</code> instead.</p>