title: Does memory allocated in a function still stay allocated after the function returns?
body: <p>For the code below:
  <strong>(1)</strong> "main" calls a function "f1".
  <strong>(2)</strong> function "f1" does some number crunching; creates an array of "char" with malloc and then, returns the pointer of the array to the main (without de-allocating -freeing- the array).</p>
  
  <p>I have 3 questions related to the case:
  <strong>(1)</strong> I assume, although the function "f1" has terminated, the allocated char array still stays allocated until the main program terminates completely. That is, the allocated memory still belongs to the main and no other process can access (I mean, interfere with) it from outside. Am I right?
  <strong>(2)</strong> Do I have to free the array (allocated in "f1") before the program terminates (or does it get freed as soon as the main program terminates) ?
  <strong>(3)</strong> If the answer for the second question is "yes" then how do you free an array allocated in another function?</p>
  
  <p>note: I want to stay within the boundaries of pure c and not to spill over to c++.</p>
  
  <pre><code>char *f1 (...) {
      ...
      ...
      char *fTmp = malloc (length1 * sizeof (char));
      char *fData = malloc (length2 * sizeof (char));
      ...
      ...
      free (fTmp);
      return (fData);
  }
  
  int main () {
      char *fData = f1 (...);
      ...
      return (0);
  }
  </code></pre>