title: Where are literal strings placed and why can I return pointers to them?
body: <p>I stumbled upon this function in an <a href="https://stackoverflow.com/a/4929561/195701">answer</a> to <a href="https://stackoverflow.com/q/4929329/195701">this question</a>:</p>
  
  <pre><code>/* Note: I've formatted the code for readability. */
  const char * getString() {
      const char *x = "abcstring";
      return x;
  }
  </code></pre>
  
  <p>I was surprised to discover that returning a pointer to the literal string worked, and didn't segfault like I thought it would. I always assumed that literals were pushed on to the stack or put in some other temporary memory, but where limited to the scope of the function. But here it seems that they are more static than I had imagined. Are they then put into something sort of string pool that's global to the entire executable? </p>
  
  <p>Also, is it the same thing if I pass a string literal as a parameter to a function? For example:</p>
  
  <pre><code>/* Where is the string literal in this example being placed? */
  myfunc(value1, value2, "rainbowdash");
  </code></pre>
  
  <p>I hope someone can enlighten me. Thanks in advance! :)</p>