title: Transposing an array
body: <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  
  void transpose(const int input[2][3], int (&amp;output)[3][2]){
      for(int i=0; i&lt;2; ++i) {
          for(int j=0; j&lt;3 ; ++j) {
              output [j][i] = input [i][j];
          }
      }
  }
  
  void printMultiArray(const int multi[2][3], const int len){
      for (int row=0; row&lt;2; row++){
          for (int col=0; col&lt;3; col++){
              cout &lt;&lt; multi[row][col] &lt;&lt; " " ;
          }                               
          cout &lt;&lt; endl;                           
      }                                               
  }   
  
  
  int main(){
  
      int multi[2][3] = {{1, 2, 3}, {7, 8, 9}};
      int empty[3][2];
  
  
      printMultiArray(multi, 6);
      cout &lt;&lt; "... space line ..." &lt;&lt; endl;
  
      transpose(multi, empty);
      printMultiArray(empty, 6);
  
  
      return 0;
  }
  </code></pre>
  
  <p>I have the above code to tranpose a 2x3 array... but it does not compile and fails with:</p>
  
  <pre><code>6-3-transposeArray.cpp: In function ‘int main()’:
  6-3-transposeArray.cpp:33: error: cannot convert ‘int (*)[2]’ to ‘const int (*)[3]’ for argument ‘1’ to ‘void printMultiArray(const int (*)[3], int)’
  </code></pre>
  
  <p>I am not sure what the problem is though. It seems to be complaining about the 1st arg to transpose() but printMultiArray() seems to have no problem with the array being passed in the same manner.</p>
  
  <p>Secondly is there a more generic way to implement this? (e.g. a generic func that could take in 2x3, 2x4 and 2x5 arrays and return the transpose of each) </p>
  
  <p>Bit of a basic question but Any help appreciated  :) </p>