title: Trying to fill a 2 dimensional array with random numbers using a function
body: <p>I'm trying to fill an array with random numbers using pointers. Here's my code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  const int mRows = 3;
  const int mCols = 5;
  
  void fillMatrix(int ** m_ptr_ptr, int, int);
  
  int main()
  {
      unsigned seed;
      seed = time(0);
      srand(47);
  
      int matrix[mRows][mCols];
      int* matrix_ptr[mRows];
      int** matrix_ptr_ptr = &amp;matrix_ptr[0];
  
  
      for (int i = 0; i &lt; mRows; i++)
      {
          matrix_ptr[i] = &amp;matrix[i][0];
      }
  
  
      fillMatrix(matrix_ptr_ptr, mRows, mCols);
  
      cout &lt;&lt; endl &lt;&lt; endl;
  
      for (int j = 0; j &lt; mRows; j++)
      {
          for (int k = 0; k &lt; mCols; k++)
          {
              cout &lt;&lt; setw(9) &lt;&lt; *((*matrix_ptr_ptr + j) + k) &lt;&lt; setw(6);
          }
              cout &lt;&lt; endl &lt;&lt; endl;
      }
  }
  
  void fillMatrix(int **matrix_ptr_ptr, int N, int P)
  {
      for (int j = 0; j &lt; N; j++)
      {
          cout &lt;&lt; left;
          for (int k = 0; k &lt; P; k++)
          {
              *((*matrix_ptr_ptr + j) + k) = rand() % 25;
              cout &lt;&lt; setw(9) &lt;&lt; *((*matrix_ptr_ptr + j) + k) &lt;&lt; setw(6);
          }
  
          cout &lt;&lt; endl &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>When I print the matrix using the <code>fillMatrix</code> function I get the following</p>
  
  <pre><code>17 24 11 0 20
  
  13 3  0 13 22
  
  20 21 11 19 18
  </code></pre>
  
  <p>After printing out the <code>matrix_ptr_ptr</code> in main by using the for loop in main I get:</p>
  
  <pre><code>17 13 20 21 11
  
  13 20 21 11 19
  
  20 21 11 19 18
  </code></pre>
  
  <p>How can I get <code>matrix_ptr_ptr</code> in main to equal the matrix outputted by the <code>fillMatrix</code> function? Any help would be appreciated</p>