vector::size function


The vector size function returns the number of elements held by the vector currently.

size_t size( ) const ;

Parameters:
none .

Return type
size_t – A unsigned int type value which is the number of elements in the vector.

Note if the capacity is non-zero but the vector holds no element then the size is still 0.

Link:vector::capacity function

Code example

vector<int>vec ={ 12 , 33 , 78 } ,
vec1 ;

vec1.reserve( 3 ) ;

cout<< vec.size( ) << endl
<< vec1.size( ) ;

Output

3
0

Although vec1 has reserve space for three elements,it holds 0 element so,size is 0.

Link:vector::reserve function


 


Stop wasting time,earn money($$$) from your website-Join Now!