二维数组做函数的参数有以下几种方法:
1、
void print(int a[][5])
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cout<<a[i][j]<<endl;
}
int main()
{
int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
print(a);
}
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cout<<a[i][j]<<endl;
}
int main()
{
int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
print(a);
}
2、
void print(int (*a)[5])
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cout<<a[i][j]<<endl;
}
int main()
{
int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
print(a);
}
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cout<<a[i][j]<<endl;
}
int main()
{
int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
print(a);
}
3、
void print(int *a)
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cout << *(a + i*5 + j) << endl;
}
int main()
{
int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
print(a[0]);
}
{
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cout << *(a + i*5 + j) << endl;
}
int main()
{
int a[5][5]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
print(a[0]);
}