C dynamicaly changing size of array using malloc and memcpy
<p>I wanted to write a function that changes the size of dynamic array and allows user to fill it at once. I know that I should do it with using of "realloc" (so I did and so it works...) but my first attempt looked like this:</p>

<pre><code>void ChangeDynamicArraySize(int* dArray, int oldSize, int newSize){

    int* tempArray = (int*) malloc(sizeof(int) * oldSize);
    CopyArray(tempArray, dArray, oldSize);
    free(dArray);
    dArray = (int*) malloc(sizeof(int) * newSize);
    CopyArray(dArray, tempArray, oldSize);

    for (int i = oldSize; i &lt; newSize; i++){
        scanf("%i", &amp;dArray[i]);
    }
    PrintArray(dArray, newSize);
    free(tempArray);
}
</code></pre>

<p>In function body  "PrintArray(dArray, newSize);" worked correct.
But when called from main() it gives a result like:
- 17891602
- 17891602
- 17891602
- 17891602</p>

<p>So it looks like dArray was freed...? But as I know allocated memmory isn't automatically freed after exiting function.</p>

<p>Then what could be the reason? </p>