您的位置:首页 > 编程语言 > C语言/C++

C++二维数组作为函数参数传递

2017-06-06 17:06 267 查看
在未知数组大小的情况下,使用指针进行传递:

第i行第j列值为*(a+i*m+j)

#include <iostream>

#include <math.h>

using namespace std;

void test(int *a, int  n, int  m)

{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cout << *(a + i*m + j) << endl;

}

void main()

{
int a[3][2] = { 1, 2, 3, 4, 5, 6 };
test((int *)a, 3, 2);
while (1);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: