title: Pointer-to-pointer dynamic two-dimensional array
body: <p>First timer on this website, so here goes..</p>
  
  <p>I'm a newbie to C++ and I'm currently working through the book "Data structures using C++ 2nd ed, of D.S. Malik". </p>
  
  <p>In the book Malik offers two ways of creating a dynamic two-dimensional array. 
  In the first method, you declare a variable to be an array of pointers, where each pointer is of type integer. ex.</p>
  
  <pre><code>int *board[4];
  </code></pre>
  
  <p>..and then use a for-loop to create the 'columns' while using the array of pointers as 'rows'.</p>
  
  <p>The second method, you use a pointer to a pointer.</p>
  
  <pre><code>int **board;
  board = new int* [10]; 
  </code></pre>
  
  <p>etc.</p>
  
  <p>My question is this: which is the better method? The ** method is easier for me to visualize, but the first method can be used in much the same way. Both ways can be used to make dynamic 2-d arrays. </p>
  
  <p>Edit: Wasn't clear enough with the above post. Here's some code I tried:</p>
  
  <pre><code>int row, col;
  
  cout &lt;&lt; "Enter row size:";
  cin &gt;&gt; row;
  cout &lt;&lt; "\ncol:";
  cin &gt;&gt; col;
  
  int *p_board[row];
  for (int i=0; i &lt; row; i++)
      p_board[i] = new int[col];
  
  for (int i=0; i &lt; row; i++)
  {
      for (int j=0; j &lt; col; j++)
      {
          p_board[i][j] = j;
          cout &lt;&lt; p_board[i][j] &lt;&lt; " ";
      }
      cout &lt;&lt; endl;
  }
  cout &lt;&lt; endl &lt;&lt; endl;
  
  int **p_p_board;
  p_p_board = new int* [row];
  for (int i=0; i &lt; row; i++)
      p_p_board[i] = new int[col];
  
  for (int i=0; i &lt; row; i++)
  {
      for (int j=0; j &lt; col; j++)
      {
          p_p_board[i][j] = j;
          cout &lt;&lt; p_p_board[i][j] &lt;&lt; " ";
      }
      cout &lt;&lt; endl;
  }
  </code></pre>