title: Copy array to dynamically allocated memory
body: <p>I got my code working, but i feel as if there is a faster way to do this especially in my function copy. here is my code. can this be any faster? this is in C btw. Also when i return cpy from the function does it delete the dynamic memory since its out of scope? I don't want to have memory leaks :P</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  double *copy(double a[], unsigned ele);
  int main(){
      double arr[8], *ptr;
      unsigned i=0;
      for(;i&lt;7;i++){
          scanf_s("%lf", &amp;arr[i]);
      }
      ptr=copy(arr, 8);
      for(i=0;i&lt;7; i++)
          printf("%f", ptr[i]);
  
  }
  
  double *copy(double a[], unsigned ele){
      double *cpy= malloc(sizeof(double)*ele);
      int i=0;
      for(;i&lt;ele; i++)
          cpy[i]=a[i];
      return cpy;
  }
  </code></pre>