title: Dynamic Allocation of two-dimensional array C++
body: <p>Hi I'm pretty new to C++ and I need to dynamicacally allocate two-dimensional array. No error but in runtime when I set a order and first row then I get a runtime error: "Segmentation Fault"...Here's code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  double ** allocateDynamicArray(int &amp;order){
      double ** arr = new double *[order];
      for(int i = 0;i &lt; order; i++){
              *arr = new double[order+1];
      }
      return arr;
  }
  void deallocateDynamicArray(double **arr, int order){
      for(int i=0; i&lt;order; i++){
          delete [] arr[i];
      }
      delete [] arr;
  }
  
  void addAndPrintArray(double **arr, int order){
      cout &lt;&lt; "Zadejte prvky pole radu " &lt;&lt; order &lt;&lt; endl;
      for(int i=0; i&lt; order; i++){
          for(int j=0; j&lt; order+1; j++){
              cout &lt;&lt; "Pole[" &lt;&lt; i &lt;&lt; "][" &lt;&lt; j &lt;&lt; "]: ";
              cin &gt;&gt; arr[i][j];
          }
      }
  
      for(int i=0; i&lt; order; i++){
          for(int j=0; j&lt; order+1; j++){
              cout &lt;&lt; arr[i][j] &lt;&lt; " ";
              if(arr[i][j] &lt; 10 &amp;&amp; arr[i][j] &gt; -10){
                  cout &lt;&lt; " ";
              }
              cout &lt;&lt; endl;
          }
      }
  }
  int main()
  {
      int order;
      cin &gt;&gt; order;
      double **dynArray = allocateDynamicArray(order);
      addAndPrintArray(dynArray, order);
      deallocateDynamicArray(dynArray, order);
      return 0;
  }
  </code></pre>