title: C++ concatenate from two arrays to one dynamic erray that are initialized from 2 input text files using filestream
body: <p>I'm trying to concatenate two arrays that were initialized from file input into one dynamic array and returning it to an output file but while testing I found out that the returned dynamic array is initialized with random numbers. I'm sorry for my lack of experience as I am a beginner.. These are my input text files</p>
  <pre><code>Input1.txt
  
  1
  2
  3
  </code></pre>
  <hr />
  <pre><code>Input2.txt
  
  4
  5
  6
  </code></pre>
  <p>and this is my code ..</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int * concatenate(int *a1,int *a2,int size);
  
  int main() {
      int size = 3;
      int arr1[size];
      int arr2[size];
      ifstream fin;
      ofstream fout;
      fin.open(&quot;input1.txt&quot;);
      for(int i = 0; i &lt; size; i++) {
          int value;
          fin&gt;&gt;arr1[i];
          cout&lt;&lt;arr1[i]&lt;&lt;endl;
      }
     fin.close();
      
      fin.open(&quot;input2.txt&quot;);
      for(int j = 0; j &lt; size; j++) {
          fin&gt;&gt;arr2[j];
          cout&lt;&lt;arr2[j]&lt;&lt;endl;
  
      }
     
      int *arr3 = concatenate(arr1,arr2,size);
      cout&lt;&lt;arr3[1];
  
      return 0;
  }
  
  int * concatenate(int *a1,int *a2,int size) {
      int * r = new int[size*2];
      for(int i = 0; i &gt; size*2; i++) {
          if(i &lt; size)
              r[i] = a1[i];
          else
              r[i] = a2[i-size];
      }
      return r;
      
  }
  </code></pre>