0

How do i pass a multidinensional array through a function

i need to pass a multidinesional array through a function to change it in that function

29th May 2019, 8:40 AM
Cat Sauce
Cat Sauce - avatar
3 ответов
+ 6
Use std::array e.g #include <iostream> #include <array> #define myMultiArray std::array<std::array<int,3>,3> void edit(myMultiArray& myMulti) { for(auto& a : myMulti) for(auto& b : a) { b++; std::cout << b << std::endl; } } int main() { myMultiArray a1 {{{1,2,3},{4,5,6},{7,8,9}}}; edit(a1); return 0; } https://code.sololearn.com/c8EFX9v2kav6/?ref=app
29th May 2019, 8:59 AM
jay
jay - avatar
0
Olin Guerrero For normal 2d arrays you can use this. void someFunc(int** ptr){ //perform some operations } for standard library containers,here's a few examples void fn(vector<vector<int>>& arr); void fn(array<array<int,5>5>& arr); void fn(deque<deque<int>> arr); Or using templates template <typename T> void fn(T& arr);
29th May 2019, 10:08 AM
Mensch
Mensch - avatar
0
Olin Guerrero For normal 2d arrays you can use this. void someFunc(int** ptr){ //perform some operations } for standard library containers,here's a few examples void fn(vector<vector<int>>& arr); void fn(array<array<int,5>5>& arr); void fn(deque<deque<int>> arr); Or using templates template <typename T> void fn(T& arr);
29th May 2019, 10:08 AM
Mensch
Mensch - avatar