给个示例程序如下:
#include <stdio.h>;
#include <stdlib.h>;
void change(int (*arr_1)[5], int (*arr_2)[6], int col,int row)
{
int col_, row_;
for (row_=0; row_<col; row_++)
{
for (col_=0; col_<row; col_++)
{
*(arr_2[row_]+col_) = *(arr_1[col_]+row_);
}
}
}
int main()
{
const int col=5, row=6;
int m,n;
int b[5][6] = {
{-1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1},
{-1, -1, -1, -1, -1, -1},
};
int a[6][5] = {
{1, 2, 3, 4, 5},
{11, 12, 13, 14, 15},
{21, 22, 23, 24, 25},
{31, 32, 33, 34, 35},
{41, 42, 43, 44, 45},
{51, 52, 53, 54, 55},
};
int (*pa)[5] = a;
int (*pb)[6] = b;
printf("In main:\n a:\n" ;
for (m=0; m<6; m++)
{
for (n=0; n<5; n++)
{
printf("%6d", *(pa[m]+n));
}
printf("\n" ;
}
printf("In main:\n b:\n" ;
for (m=0; m<5; m++)
{
for (n=0; n<6; n++)
{
printf("%6d", b[m][n]);
}
printf("\n" ;
}
change (pa, pb, col, row);
printf("After change:\n a:\n" ;
for (m=0; m<row; m++)
{
for (n=0; n<col; n++)
{
printf("%6d", a[m][n]);
}
printf("\n" ;
}
printf("After change:\n b:\n" ;
for (m=0; m<5; m++)
{
for (n=0; n<6; n++)
{
printf("%6d", b[m][n]);
}
printf("\n" ;
}
return 0;
} |