您好,欢迎来到榕意旅游网。
搜索
您的当前位置:首页VS2017学习C++基础十二(使用二维数组作为函数参数)

VS2017学习C++基础十二(使用二维数组作为函数参数)

来源:榕意旅游网
#include <iostream>
using namespace std;
//声明函数
void showArray(double(*)[5], int len);  

/*
* 不允许修改数组中的元素,使用常量 const
* void showArray(const double(*)[5], int len);
* void showArray(double(*arrs)[5], int len)
*/

//定义函数
void showArray(double(*arrs)[5], int len)
{
	for (int i = 0; i < len; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			cout << arrs[i][j] << '\t';
		}
		cout << endl;
	}
}

int main()
{
	double powers[3][5] = { {12, 13, 14, 15, 16},{20.5, 21.5, 22.5, 23.5, 24.5}, {30, 31, 32, 33, 34} };
	showArray(powers, 3);
}

结果为:

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- nryq.cn 版权所有 赣ICP备2024042798号-6

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务