C++: How do I assign a value from a 2D dynamic array to another 2D dynamic array since 'temp[0][0] = array[0][0]' doesn't work? : <p>I'm new to c++, and I'm trying to figure out how to get a 2D dynamic array called temp to get values from another 2D dynamic array called array. I couldn't figure out how to assign any values from array to temp because the statement 'temp[0][0] = array[0][0];' doesn't seem to assign the value of array[0][0] which is 1 to temp[0][0]. Instead, temp[0][0] seems to have the same random number in it after 'temp[0][0] = array[0][0]' before any value was assign to temp[0][0]. I tried to assign temp[0][0] to 2 and it works. I don't really know how to exactly assign values from one 2d dynamic array to another. Anyway thanks in advance for helping me out!</p>

<pre><code>    ...
    //initializing first 2D dynamic array
    int x=2;
    int y=2;
    int** array = new int*[x];
    for(int i=0; i&lt;x; i++) array[i] = new int[y];

    //initializing second 2D dynamic array
    int new_x=3;
    int new_y=3;
    int** temp = new int*[new_x];
    for(int i=0; i&lt;new_x; i++) temp[i] = new int[new_y];

    //assigning values
    array[0][0] = 1;
    cout &lt;&lt; array[0][0] &lt;&lt; endl; //output is 1

    //before assigning values to temp[0][0]
    cout &lt;&lt; temp[0][0] &lt;&lt; endl; //out is a huge random number

    temp[0][0] = array[0][0]; 
    cout &lt;&lt; temp[0][0] &lt;&lt; endl; //output is the same huge random number


    temp[0][0] = 2;
    cout &lt;&lt; temp[0][0] &lt;&lt; endl; //output is 2
    ...
</code></pre>
