cc++中三维数组的传递

    xiaoxiao2022-07-02  93

    #include <iostream> #include <windows.h> using namespace std; const int x = 10; const int y = 10; const int z = 10; int bar(double arr[][y][z]); int main() { double foo[x][y][z]; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { for (int k = 0; k < z; k++) { foo[i][j][k] = 1.0; } } } cout << foo[0][0][0] << endl; // 1.0 bar(foo); system("pause"); return 0; } int bar(double arr[][y][z]) { cout << "function invoked value: " << arr[1][1][1] << endl; return 0; }

    输出结果为

    1 function invoked value1

    注意,在传递三维数组作为参数时,数组的第一个[]中为空,而第二第三个不能为空。

    这样,对于大部分情况下的三维数组就可以轻松处理了。

    本文转自 https://www.cnblogs.com/zhuzhenwei918/p/8849644.html

    最新回复(0)