sizeof()
gives you the number of bytes in memory that the object is occupying. The class std::vector
is a container that has its own member variables to manage the internal array that it is representing, and they are counted as well as part of the size. Both a
and b
in your case are too small in number of elements to make it reallocate its internal array to hold more than what it initially uses to hold a single element.
For illustration, my compiler returns 32 for both these cases:
#include <vector>
int main()
{
std::vector<int> a{ 1 };
std::vector<int> b{ 1,2,3,4,5 };
int sizeA = sizeof(a); // Returns 32
int sizeB = sizeof(b); // Returns 32
return 0;
}