How to Find the Capacity of a Vector in Bytes in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 5 Likes Like Report In C++, vectors are used to store the collection of similar types of data and are able to automatically resize themself in order to accommodate more data. In this article, we will discuss how to calculate the capacity of a vector in bytes. For Example Input: myVector = {10, 34, 12, 90, 1}; Output: 20 bytesCapacity of Vectors in BytesIn STL, there is no direct method to get the size of the vector in bytes. However, we can estimate the capacity in bytes by multiplying the capacity (number of elements the vector can hold without reallocation) by the size of each element. We can find the capacity of the vector by using the std::vector::capacity() function and to find the size of each element.We can use the sizeof operator on any of the vector elements accessed by the index.C++ Program to Find the Capacity of Vector in Bytes C++ // C++ Program to Calculate Capacity of vector in bytes #include <iostream> #include <vector> using namespace std; int main() { // Vector of integers vector<int> myVector = { 10, 20, 30, 40, 50 }; // Size of Each Element size_t size = sizeof(myVector[0]); cout << "Size of Each Element in Bytes: " << size << " bytes" << endl; // Capacity of Vector size_t size_of_vector = myVector.capacity(); // Size of Vector in Bytes size_t size_In_Bytes = size * size_of_vector; cout << "Capacity of Vector in bytes: " << size_In_Bytes << " bytes" << endl; return 0; } OutputSize of Each Element in Bytes: 4 bytes Capacity of Vector in bytes: 20 bytes Time Complexity : O(1)Space Complexity : O(1) Comment O officialsi8v5f Follow 5 Improve O officialsi8v5f Follow 5 Improve Article Tags : C++ Programs C++ cpp-data-types cpp-vector cpp-sizeof CPP Examples +2 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like