title: Merge Sort in C++: Unable to pass array in merge function - invalid conversion to 'int*'
body: <p>I am trying write a merge sort function in C++, however I am getting an error on (in the MergeSort function):</p>
  
  <pre><code>    A = MergeSort (A, x);
      B = MergeSort (B, y);
      C = Merge(A,B,x,y);
  </code></pre>
  
  <p>as an invalid conversion from int to int*. What am I doing wrong? Any help will be greatly appreciated! Thanks.</p>
  
  <p>Here is my function code:</p>
  
  <pre><code>int MergeSort (int [], int);
  int Merge (int [], int [], int, int);
  
  
  int MergeSort (int arr[], int len) {
      int x = len/2;
      int y = len-x;
      int i,j;
  
      // initialize the arrays
      int * A = new int [x];
      int * B = new int [y];
      int * C = new int [len];
  
      // copy left and right arrays
      for (i=0, j=0; i&lt;x; i++, j++) {
          A[i] = arr[j];
      }
  
      for (i=0; i&lt;y; i++, j++) {
          B[i] = arr[j];
      }
  
      A = MergeSort (A, x);
      B = MergeSort (B, y);
      C = Merge(A,B,x,y);
  
      return C;
  }
  
  int Merge(int A[], int B[], int x, int y) {
      int i,j,k;
      i = 0; j = 0; k = 0;
  
      int * C = new int[x+y];
  
      while (i &lt; x &amp;&amp; j &lt; y) {
          if (A[i] &lt; B[j])
              C[k++] = A[i++];
          else
              C[k++] = B[j++];
      }
  
      if (i &lt; x) //A is longer
          C[k++] = A[i++];
      if (j &lt; y) //B is longer
          C[k++] = B[j++];
  
      return C;
  
  }
  </code></pre>
  
  <p>And here is my main function:</p>
  
  <pre><code>int main() {
  
      //initialize array with some values
      int ar [8] = {7, 5, 9, 1, 4, 22, 11, 10};
  
      cout&lt;&lt;"array:";
      for (int i=0;i&lt;8;i++)
          cout&lt;&lt;ar[i];
      cout&lt;&lt;endl;
  
      //run merge sort
      ar = MergeSort(ar,8);
  
      cout&lt;&lt;"merged array:";
          for (int i=0;i&lt;8;i++)
              cout&lt;&lt;arr[i];
          cout&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>