![]() |
VOOZH | about |
// Creates a vector vect[] of size 10 vector <int> vect(10) // creates an array of vectors vect[] of size // 10 where each vector has int members vector<int> vect[10]
Output: 0 1 2 3 4 0 0 0 0 0 0 1 2 3 4 0 0 0 0 0 50
// This doesn't work vector<vector<int>> vect; // This works fine vector< vector <int> > vect;The difference between these two statements is that the first statement has a space between the angular brackets ( > >). Writing without the space doesn't work because >> is an operator in C++.
10 20In situations where we don’t actually need to have a copy of the vector, the declaration should be made as follows:
// It is recommended to pass vectors by reference
// wherever possible.
int func(vector<int>& vect)
{
}