title: swapping array rows and printing, c
body: <p>this is something that's been bugging me for the past two hours. I'm trying to swap two rows in a two dimensional array. This is not a problem, but I want to do it with a swap function that gets pointers. Here's what I have so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void swapRows(int **a, char **b)
  {
      int *temp = *a;
      *a = *b; // WARNING #1
      *b = temp; // WARNING #1
  
  }
  
  void print(int a[][2],int rows,int cols)
  {
      int i,j;
      for (i=0; i&lt;rows; i++)
      {
          for (j=0; j&lt;rows; j++)
          {
              printf("%d ",a[i][j]);
          }
          printf("\n");
      }
  }
  
  int main(void)
  {
      int matrix[2][2] = {{1,2},{3,4}};
      print(matrix,2,2);
      swapRows(&amp;matrix[0],&amp;matrix[1]); //WARNING #2
      print(matrix,2,2);
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>So, here are my questions:</p>
  
  <p>1)The swap functions only swaps between the first elements in each array, which makes sense.  How do I get it to swap the other elements? Do I HAVE to iterate the entire row?</p>
  
  <p>2)When declaring print it only worked if i set <code>a[][]2</code>. Before that I tried writing <code>int **arr</code> but I had a segmentation fault. Why is that? Also, why must I specify the number of cols in the array argument? I have rows and cols for that, why does the compiler forces me to do so?</p>
  
  <p>3)finally, using this version of <code>print()</code> I get a warning from the compiler <code>passing argument 2 of ‘swapRows’ from incompatible pointer type</code> (warning #2 in the code) and I get another warning (#1) : <code>assignment from incompatible pointer type</code> in <code>swapRows()</code>. Why is that?
  Thanks in advance!</p>