title: C: do all string literals have static storage duration?
body: <p>I've been reading in various sources that string literals remain in memory for the whole lifetime of the program. In that case, what is the difference between those two functions</p>
  
  <pre class="lang-c prettyprint-override"><code>char *f1() { return "hello"; }
  char *f2() {
     char str[] = "hello";
     return str;
  }
  </code></pre>
  
  <p>While <code>f1</code> compiles fine, <code>f2</code> complains that I'm returning stack allocated data. What happens here?</p>
  
  <ul>
  <li>if the <code>str</code> points to the <em>actual</em> string literal (which has static duration), why do I get an error?</li>
  <li>if the string literal is copied to the local variable <code>str</code>, where does the original string literal go? does it remain in memory with no reference to it?</li>
  </ul>