法一
void show(double (*)[5], int); //函数声明
void show(double (*arr)[5], int len){ }; //函数实现
#include <iostream>
using namespace std;
void show(double (*)[5], int);
int main()
{
double powers[3][5] = {
{45.5, 55.6, 88.9, 66.6, 78},
{98.2, 69.1, 33.7, 49.3, 58},
{78.2, 58.5, 12.8, 37.8, 43},
};
show(powers, 3);
return 0;
}
void show(double (*arr)[5], int len)
{
for(int i = 0; i < len; i++)
{
for(int j = 0; j < 5; j++)
{
//等价于cout << arr[i][j] << " ";
cout << *(*(arr + i)+j) << " ";
}
cout << endl;
}
}
法二
void show(double [][5], int); //函数声明
void show(double arr[][5], int len) { }; //函数实现
#include <iostream>
using namespace std;
void show(double [][5], int);
int main()
{
double powers[3][5] = {
{45.5, 55.6, 88.9, 66.6, 78},
{98.2, 69.1, 33.7, 49.3, 58},
{78.2, 58.5, 12.8, 37.8, 43},
};
show(powers, 3);
return 0;
}
void show(double arr[][5], int len)
{
for(int i = 0; i < len; i++)
{
for(int j = 0; j < 5; j++)
{
//等价于cout << arr[i][j] << " ";
cout << *(*(arr + i)+j) << " ";
}
cout << endl;
}
}
如果是string类呢?
把double类型改为string即可
#include <iostream>
using namespace std;
void show(string (*)[5], int);
int main()
{
string powers[2][5] = {
{"东邪黄药师", "西毒欧阳锋", "南帝段智兴", "北丐洪七公", "中神通王重阳"},
{"东邪黄药师", "西狂杨过", "南僧一灯", "北侠郭靖", "中顽童周伯通"},
};
show(powers, 2);
return 0;
}
void show(string (*arr)[5], int len)
{
for(int i = 0; i < len; i++)
{
for(int j = 0; j < 5; j++)
{
//等价于cout << arr[i][j] << " ";
cout << *(*(arr + i)+j) << " ";
}
cout << endl;
}
}