how to pass 2d vector to a function code example
Example: passing 2d vector to function
void printFunc(vector < vector<int> > vec)
{
for(int i=0; i<vec.size(); i++)
for(int j=0; j<vec[i].size(); j++)
cout<<vec[i][j]<<" ";
cout<<endl;
}
int main()
{
int rows = 2;
int cols = 2;
int val = 1;
/*creates 2d vector “v[rows][cols]”
and initializes all elements to “val = 1”*/
vector< vector<int> > v(rows, vector<int> (cols, val));
printFunc(v);
}