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