title: C++ management of strings allocated by a literal
body: <p>Do I need to take care of memory allocation, scope and deletion of C++ strings allocated by a literal?</p>
  <p>For example:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;string&gt;
  
  const char* func1() {
      const char* s = &quot;this is a literal string&quot;;
      return s;
  }
  
  string func2() {
      std::string s = &quot;this is a literal string&quot;;
      return s;
  }
  
  const char* func3() {
      std::string s = &quot;this is a literal string&quot;;
      return s.c_str();
  }
  
  void func() {
      const char*  s1 = func1();
      std::string s2 = func2();
      const char*  s3 = func3();
  
      delete s1; //?
      delete s3; //?
  }
  </code></pre>
  <ul>
  <li><code>func2</code>: I don't need to <code>delete s2</code>.</li>
  <li><code>func3</code>: Do I need to <code>delete s3</code>?</li>
  </ul>
  <p>Is <code>func1</code> correct? Is character memory content still available after it leaving <code>func1</code>'s scope? If yes, should I delete it when I do not need it anymore?</p>