title: Deleting allocated array within function vs in main
body: <p>If I declare a allocated pointer inside main</p>
  
  <pre><code>char *ch2=new char[10*17]; 
  char *ch2p=ch2; 
  while(infile.get(*ch2))
  {
  cout&lt;&lt;*ch2;
  ch2++;
  }
  .................................
  char *zc=rc.sortArray(ch2p,10,17);
  </code></pre>
  
  <p>inside the function I copy over the array into a new one that gets returned to main </p>
  
  <pre><code>T* a_ray = new T[(10*17)];
  for(int i=0;i&lt;rows;i++) 
  {
      for(int j=0;j&lt;cols;j++)
      {
          a_ray[i*cols+j] = arry[i*cols+j];
      }
  }
  </code></pre>
  
  <p>Now my questions are,  I added this into the function, </p>
  
  <pre><code> delete [] arry; // delete old array
  </code></pre>
  
  <p>So I can delete the array created in main after copying it over into the new one that gets returned in main as zc <em>look at code above</em> but if I run a loop in main displaying the contents of the array, it shows all the contents as if the delete in function didn't work but when I deleted in main nothing shows up in loop <em>so I assume it is deleted</em>
  so,</p>
  
  <p>1)my first question is why does deleting in function not work?</p>
  
  <p>2)the line.</p>
  
  <pre><code>char *ch2p=ch2; 
  </code></pre>
  
  <p>is this a pointer to another pointer? and does this need to be deleted or do I jsut delete the ch2?</p>
  
  <p>Thank you for any responses, also note this code is snippets from my class which is now over so I can't get answers to it.</p>