xxxxxxxxxx
Returns the size of the storage space currently allocated for the vector, expressed in terms of elements. This capacity is not necessarily equal to the vector size. It can be equal or greater, with the extra space allowing to accommodate for growth without the need to reallocate on each insertion.
xxxxxxxxxx
// CPP program to create an empty vector
// and push values one by one.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n = 3;
// Create a vector of size n with
// all values as 10.
vector<int> vect(n, 10);
for (int x : vect)
cout << x << " ";
return 0;
}
xxxxxxxxxx
// create a vector with 20 integer elements
std::vector<int> arr(20);
for(int x = 0; x < 20; ++x)
arr[x] = x;