capacity(): It returns the total number of elements that the vector can hold before needing to
allocate more memory.
Syntax:
vecName.capacity():
File: stl_vector.h
For Example:
vec = {1,2,3,4,5}
vec.capacity() = > It returns 8.
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){vector<int> vec;for (int i = 1; i <= 5; i++)vec.push_back(i);cout << vec.capacity() << "\n";return 0;}
No comments:
Post a Comment