title: 2D dynamic memory allocation array in C++
body: <p>A few days ago I learned about creating 2D allocated memory arrays from the internet, it works perfect. To access the array we just simply use <code>matrix[i][j]</code>, however is there any way that I can dereference this 2D array by using <code>*</code> notation instead of <code>[]</code> for input as well as other methods?</p>
  
  <p>First questions is solved I can use <code>*(*(matrix + i) + j)</code></p>
  
  <p>Now I got another question, last code segment is to free the allocated memory (I got it from internet as well), but I don't understand it, why cant I just use <code>delete [] matrix</code> ?</p>
  
  <pre><code>int **matrix;
  
  // dynamically allocate an array
  matrix = new int *[row]; 
  for (int count = 0; count &lt; row; count++)
  {
      matrix[count] = new int[col];
  }
  
  // input element for matrix
  cout &lt;&lt; endl &lt;&lt; "Now enter the element for the matrix..."; 
  for (int i=0; i &lt; row; i++) 
  {
      for (int j=0; j &lt; col; j++)
      {
          cout &lt;&lt; endl &lt;&lt; "Row " &lt;&lt; (i+1) &lt;&lt; " Col " &lt;&lt; (j+1) &lt;&lt; " :";
          cin &gt;&gt; matrix[i][j]; // is there any equivalent declaration here?
      }
  }
  
  // free dynamically allocated memory
  for( int i = 0 ; i &lt; *row ; i++ )
  {
      delete [] matrix[i] ;   
  }
  delete [] matrix ;
  </code></pre>