C++ vector::pop_back function

The C++ vector pop_back function of vector removes the last element of the vector.

void pop_back();

Parameters:
none

Return type
none

This function will only decrease the size of the vector not the capacity of the vector.And after the function is called the data is lost forever.

 vector<int> vec={ 12 , 23 , 4 } ;

vec.pop_back( ) ;

vec.reserve( 5 ) ;

for( auto elem:vec )
{
cout<< elem << ” “;
}

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

Output

12 23
2
5



Leave a Reply

Your email address will not be published. Required fields are marked *