Free a pointer equal to a malloc pointer
<p>I'm having trouble understanding some of the free() behavior.</p>

<pre><code>int* ptr1 = (int*)malloc(sizeof (int)*10);
int* ptr2 = ptr1;
free(ptr2);
</code></pre>

<p>Is the <code>free(ptr2)</code> going to delete my array as I want ?</p>

<p>What if I do :</p>

<pre><code>int** ptr1 = (int**)malloc(sizeof (int)*10);
int* ptr2 = (int*)malloc(sizeof (int));
*ptr2 = 10;
ptr1[0] = ptr2;
free(ptr1);
</code></pre>

<p>Is this code correct ? Will <code>free(ptr1)</code> will also delete the space of ptr2 ?</p>

<p>Thanks</p>