How to Find the Size of a Vector in Bytes in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report In C++, Vectors are dynamic containers that can change their size during the insertion or deletion of elements. In this article, we will explore how we can find the size of the vector in bytes in C++. Example: Input:myVector = {10,20,30,40,50}Output:Size of the vector in bytes is : 20 bytesFind the Size of a Vector in Bytes in C++There is no direct method in C++ that can find the size of a vector in bytes. However, we can use the vector::size() method to find the number of elements in the vector and multiply it by the size of a single element which can be found using sizeof() operator. C++ Program to Find the Size of a Vector in Bytes C++ // C++ program to find the size of a vector in bytes #include <iostream> #include <vector> using namespace std; int main() { // Initialize a vector with few elements vector<int> vec = { 10, 20, 30, 40, 50 }; // Calculate the size of the vector int vecSize = vec.size(); // Calculate the size of any individual element in the // vector int elementSize = sizeof(vec[0]); // Calculate the size of the vector in bytes int size = vecSize * elementSize; cout << "Size of the vector in bytes is : " << size << endl; return 0; } OutputSize of the vector in bytes is : 20 Time Complexity: O(1)Auxiliary Space: O(1) Create Quiz Comment G gaurav472 Follow 1 Improve G gaurav472 Follow 1 Improve Article Tags : C++ Programs C++ STL cpp-vector CPP Examples +1 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