如何理解:
    数组名其实是首元素的指针。

    以m*n矩阵转置函数为例:

    1. #include <iostream>
    2. #include <stdio.h>
    3. using namespace std;
    4. const int m = 3;
    5. const int n = 2;
    6. typedef int(*R)[m];
    7. R TransMatrix(const int a[][n] , int b [][m]) {
    8. for (size_t i = 0; i < m; i++) {
    9. for (size_t j = 0; j < n; j++)
    10. {
    11. b[j][i] = a[i][j];
    12. }
    13. }
    14. return b;
    15. }
    16. void ShowMatrix(int* a , const int irows, const int icols) {
    17. for (size_t i = 0; i < irows; i++) {
    18. for (size_t j = 0; j < icols; j++)
    19. {
    20. cout <<*(a+i*icols+j) << " ";
    21. }
    22. cout << endl;
    23. }
    24. }
    25. int main()
    26. {
    27. int A[m][n];
    28. int B[n][m];
    29. cout << "请输入数组" << endl;
    30. for (size_t i = 0; i < m; i++) {
    31. for (size_t j = 0; j < n; j++)
    32. {
    33. cin >> A[i][j];
    34. }
    35. }
    36. cout << "----------输入的数组是:-----------" << endl;
    37. ShowMatrix((int*)A,m,n);
    38. cout << "----------转置是:-----------" << endl;
    39. ShowMatrix((int*)TransMatrix(A,B), n, m);
    40. return 0;
    41. }