Vector Pop Back Function - C++ Programming Tutorial
C++ Course / STL Vector / Vector Pop Back Function

Vector Pop Back Function

BLUF: Mastering Vector Pop Back Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Vector Pop Back Function

C++ is renowned for its efficiency. Learn how Vector Pop Back Function enables low-level control and high-performance computing in the tutorial below.

C++ Vector pop_back

It removes the final element and decreases the vector's size by one.

Syntax

Consider a vector v.Syntax would be:

Example

v.pop_back();

Parameter

It does not contain any parameter.

Return value

It does not return any value.

The diagram below demonstrates the functionality of the pop_back method:

This diagram demonstrates the removal of the final element in a vector using the pop_back method.

Example

Let's see a simple example.

Example

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v{"welcome","to","javaCppTutorial","tutorial"};
cout<<"Initial string is :";
for(inti=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<'\n';
cout<<"After deleting last string, string is :";
v.pop_back();
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
return 0;
}

Output:

Output

Initial string is :welcome to javaCppTutorial tutorial 
After deleting last string, string is :welcome to javaCppTutorial

In this instance, the final string is eliminated using the pop_back method.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience