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

xiaoxiao2021-02-27  162

在未知数组大小的情况下,使用指针进行传递:

第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); }

转载请注明原文地址: https://www.6miu.com/read-16473.html

最新回复(0)