In C + +, we can define three-dimensional arrays, and we can pass them directly as parameters.
Defined:
#include <iostream>#include<windows.h>using namespacestd;Const intx =Ten;Const inty =Ten;Const intz =Ten;intMain () {DoubleFoo[x][y][z]; for(inti =0; i < x; i++) { for(intj =0; J < y; J + +) { for(intK =0; K < Z; k++) {Foo[i][j][k]=1.0; } }} cout<< foo[0][0][0] << Endl;//1.0System"Pause"); return 0;}
As shown above, we set a static array, so we must determine its size before defining the three-dimensional array, and for the maintainability of the program, we recommend that you define it with a const int.
To pass a three-dimensional array as a parameter:
#include <iostream>#include<windows.h>using namespacestd;Const intx =Ten;Const inty =Ten;Const intz =Ten;intBarDoublearr[][y][z]);intMain () {DoubleFoo[x][y][z]; for(inti =0; i < x; i++) { for(intj =0; J < y; J + +) { for(intK =0; K < Z; k++) {Foo[i][j][k]=1.0; } }} cout<< foo[0][0][0] << Endl;//1.0Bar (foo); System ("Pause"); return 0;}intBarDoubleArr[][y][z]) {cout<<"function invoked value:"<< arr[1][1][1] <<Endl; return 0;}
As shown above, the end result is:
1 function invoked value1
Note that when you pass a three-dimensional array as a parameter, the first [] of the array is empty, and the second third cannot be empty.
This makes it easy to handle three-dimensional arrays in most cases.
Definition of C + + three-dimensional static array and its transfer as function