![]() |
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 bytes Capacity 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.
C++ Program to Find the Capacity of Vector in BytesC++
Output
Size of Each Element in Bytes: 4 bytes Capacity of Vector in bytes: 20 bytes Time Complexity : O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |