forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
capacity.cpp
27 lines (22 loc) · 852 Bytes
/
capacity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide
/*
Author : Y. Sai Sriram
Date : 28/09/2019
Time : 10:17
Description : Returns the space currently allocated to the vector
*/
#include <iostream>
#include <vector>
int main()
{
// create a vector of 10 integers
std::vector<int> myvector{10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
// display the capacity of vector, because no value has been pushed, it returns the size of vector
std::cout << "The capacity of the vector is: " << myvector.capacity();
myvector.push_back(110);
std::cout << std::endl;
// notice how capacity returns a value greater than 11... it stores extra memory for further allocation
std::cout << "The capacity of the vector is: " << myvector.capacity();
std::cout << std::endl;
return 0;
}