title: Does using malloc in method, free in main work?
body: <p>I have the following question:</p>
  
  <p>If I use <code>malloc</code> in a method, <code>return</code> the pointer to my <code>main</code>, and <code>free</code> the pointer in my main, do i have successfully freed the memory or not? And is this bad programming style, if i do so?</p>
  
  <pre><code>int* mallocTest(int size)
  {
      int * array = (int*) malloc(size);
      return array;
  }
  
  int main ()
  {
      int* pArray = mallocTest(5);
      free (pArray);
      return 0;
  }
  </code></pre>
  
  <p>EDIT: The main purpose of this question is that I want to know, if I freed the memory successfully (if i use the right "combination" of malloc-free/new[]-delete[]) when i split this into the method and the main function!</p>
  
  <p>EDIT2: Changed code and topic, to lead to the intended point of the question</p>