将2D数组传递给C ++函数
数组可以作为参数传递给函数。在此程序中,我们将通过将二维数组的元素传递给函数来执行其显示。
算法
Begin The 2D array n[][] passed to the function show(). Call function show() function, the array n (n) is traversed using a nested for loop. End
范例程式码
#include <iostream>
using namespace std;
void show(int n[4][3]);
int main() {
int n[4][3] = {
{3, 4 ,2},
{9, 5 ,1},
{7, 6, 2},
{4, 8, 1}};
show(n);
return 0;
}
void show(int n[][3]) {
cout << "Printing Values: " << endl;
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 3; ++j) {
cout << n[i][j] << " ";
}
}
}输出结果
Printing Values: 3 4 2 9 5 1 7 6 2 4 8 1
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短