title: return a local pointer which points to a static variable
body: <p>Here is the code,</p>
  
  <pre><code>char *foo()
  {
      static char s[10] = "abcde";
      return s;
  }
  
  char *bar()
  {
      char *c = foo();
      return c;
  }
  
  int main()
  {
      printf("%s\n", bar()); 
  }
  </code></pre>
  
  <p>Typically, it is wrong to return a local pointer as I did in <code>bar</code>, but now <code>c</code> points to a <code>static</code> var returned by <code>foo</code>, would it be correct to return a local var <code>c</code> in <code>bar</code>?</p>
  
  <p>I tried, it <code>printf</code> the right value, but I don't understand how it works. I thought, when <code>bar()</code> finishes, the var <code>c</code> should vanish, which should make <code>printf</code> print undefined stuff, right?</p>
  
  <p><strong>Follow Up</strong></p>
  
  <p><code>char *c</code> is a local var, if <code>char *c = "abcde";</code>, I assume this: <code>c</code> is a local var which resides in the function's stack, while <code>"abcde"</code> is a constant var which resides in the constants-area (part of the heap?), so when <code>bar()</code> finishes, <code>c</code> vanishes, but <code>"abcde"</code> still remains in the heap, right?</p>