title: Swapping 2 arrays in C
body: <p>I need to swap the values of 2 arrays in a function. The problem is I can change anything in the main, just the function itself. It should recive 2 integer arrays, and swap those. The problem is, that I don't know the size of the arrays, and for my understading they can even be in diffrent sizes. Trying this code:</p>
  
  <pre><code>    int main()
  {
      int size = 4;  //Please notice that I'm using this only to print the array
      int a[] = {1,2,3,4};
      int b[] = {5,6,7,8};
      printArr(a,"a",size);
      printArr(b,"b",size);
      swapArray(a,b);
      printf("Swapped:\n");
      printArr(a,"a",size);
      printArr(b,"b",size);
  }
  </code></pre>
  
  <p>and this function:</p>
  
  <pre><code> void swapArray(int **a,int **b)
  {
      int *p = *a;
      *a = *b;
      *b = p;
  }
  </code></pre>
  
  <p>while printArr simply prints the array:</p>
  
  <pre><code>void printArr(int arr[],char name[],int size)
  {
      printf("%s:\t",name);
      for(int i=0;i&lt;size;i++){
          printf("%d\t",arr[i]);
      }
      printf("\n");
  }
  </code></pre>
  
  <p>I got a really weird result:</p>
  
  <pre><code>a:   1    2    3   4
  b:   5    6    7   8
  Swapped:
  a:   5    6    3   4
  b:   1    2    7   8
  </code></pre>
  
  <p>I would like to understand why it happens, and not only a working solution. 
  Thank you :)</p>