title: Copy a 2D array to other 2D array that unknown size in C++
body: <p>I have a question about dynamic 2D array returning. That means I don't know size of returning 2D array (It depends on some condition). Let see my problem</p>
  
  <pre><code>N=3; 
  A[N][5]={}//Given a 2D array
  for i=1 to N
     x=random between 0 and 1
     k=1;
     while(k&lt;N&amp;&amp;x&gt;0.3)
  
      k++;
      B_i=A_k //Look like copy value of array A to array B at position k
  </code></pre>
  
  <p>My problem is that I don't know the value of k, it depends on <code>(k&lt;N&amp;&amp;x&gt;0.3)</code>. Hence, I cannot initial the array B. Could you suggest to me one way to do it? This is my code that I tried</p>
  
  <pre><code>int A[2][5] =
      {
          {1,8,12,20,25},
          {5,9,13,24,26},
          {15,1,5,2,22}
      };
  
  
  int N=3;
     for(int i=0;i&lt;N;i++) 
     {
     double x=random();//create random number between 0 and 1.
     int k=0;
     while(k&lt;N&amp;&amp;x&gt;0.3)
       {
       k++;
       B[k][4]=A[i][4]; //I have no idea to initial 2D array B
       }
     }
  </code></pre>