Problems with dynamic array creation using pointers
<p>I'm trying to create a 2d dynamic array using the values of an array of <code>int</code> as my pointers. I don't know how to put this in words exactly, so here is the code.  Maybe you'll understand what I'm trying to do if you see it.</p>

<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;
using namespace std;

int main(){
    const int length =5;
    int arr[5]={1,1,3,9,1};
    int* AR[length];

    for (int i=0; i&lt;length;i++) {
        for (int j=0; j&lt;(arr[i]); j++){
            AR[i] = new int (arr[i]);
            AR[i][j]=93;
            cout&lt;&lt;"["&lt;&lt;AR[i][j]&lt;&lt;"] ";
        }
        cout&lt;&lt;endl;
    }

    for (int i = 0; i &lt; length; i++) {
        for (int j=0; j&lt;arr[i]; j++) {
            delete[] AR[i];  
            delete []&amp;AR;
        }
    }
    return 0;
}
</code></pre>

<p>Whenever I run it with <code>arr[] &lt; 4</code> it runs perfectly, but if the size of <code>arr</code> exceeds 4 values it crashes.  Can you see why?</p>
