Pointer arithmetics. core dumped
<p>This is my small code. It works fine until dim=3. If I enter dim=4 I get this strange error:</p>

<p>makefile:10: recipe for target 'exec' failed
make: *** [exec] Aborted (core dumped)</p>

<p>I think "core dumped" appears when I try to access memory which I do not own but I cant see where the mistake is in this code.</p>

<pre><code>  1 #include &lt;iostream&gt;
  2 
  3 using namespace std;
  4 
  5 int main(){
  6         int dim = 0;
  7         double* y = new double[dim+1];
  8         double* x = new double[dim+1];
  9 
 10         do{
 11                 cout &lt;&lt; "Enter a dimension:\n";
 12                 cin &gt;&gt; dim;
 13                 if(dim&lt;=0) cerr &lt;&lt; "Error: Dimension is lower equal 0!\n";
 14         }while(dim&lt;=0);
 15 
 16         for(int i = 0; i&lt;dim; i++){
 17                 *(y+i) = dim*i + 7;
 18                 *(x+i) = dim*i + 1;
 19                 cout &lt;&lt; "*(y+" &lt;&lt; i &lt;&lt; "): " &lt;&lt; *(y+i) &lt;&lt; "\t" &lt;&lt; "*(x+" &lt;&lt; i &lt;&lt; "): " &lt;&lt; *(x+i) &lt;&lt; endl;
 20         }
 21 
 22         
 23         
 24         delete[] y;
 25         delete[] x;
 26         return 0;
 27 }
</code></pre>