在未知数组大小的情况下,使用指针进行传递:
第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); }