二维数组做函数参数的几种情况
#include <stdio.h>
void _fun1(int a[2][3])
{
printf("_fun1:\n");
int i,j;
for (i=0; i<2; i++)
{
for (j=0; j<3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
printf("\n");
}
void _fun2(int a[][3], int n)
{
printf("_fun2:\n");
int i,j;
for (i=0; i<n; i++)
{
for (j=0; j<3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
printf("\n");
}
void _fun3(int (*a)[3], int n)
{
printf("_fun3:\n");
int i,j;
for (i=0; i<n; i++)
{
for (j=0; j<3; j++)
printf("%d ", a[i][j]);
printf("\n");
}
printf("\n");
}
void _fun4(int *a, int n, int m)
{
printf("_fun4:\n");
int i,j;
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
printf("%d ", *(a+m*i+j));
printf("\n");
}
printf("\n");
}
void _fun5(int *a[], int n, int m)
{
printf("_fun5:\n");
int i,j;
for (i=0; i<n; i++)
{
for (j=0; j<m; j++)
printf("%d ", a[i][j]);
printf("\n");
}
printf("\n");
}
void _fun6(int *a, int n)
{
printf("_fun6:\n");
int i;
for (i=0; i<n; i++)
printf("%d ", a[i]);
printf("\n");
}
main()
{
int a[2][3]= {1,2,3,4,5,6};
_fun1(a);
_fun2(a, 2);
_fun3(a, 2);
_fun4(*a, 2, 3);
int i, *b[2];
for(i=0; i<2; i++)
b[i] = a[i];
_fun5(b, 2, 3);
_fun6(*a, 6);
}