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

Vector Push Back Function

BLUF: Mastering Vector Push 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 Push Back Function

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

C++ Vector push_back

This function appends a new item to the vector.

Syntax

Consider a vector v and let 'k' represent the value. The syntax would be:

Example

v.push_back(k)

Parameter

k : k represents the specific value that will be added to the vector at its conclusion.

Return value

This function does not return any value.

The upcoming diagram demonstrates the functionality of the push_back method:

This diagram demonstrates that the push_back method adds a new element at the back.

Example

Let's see a simple example.

Example

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<char> v;
	v.push_back('j');
	v.push_back('a');
	v.push_back('v');
	v.push_back('a');
	for(int i=0;i<v.size();i++)
	cout<<v[i];
	return 0;
}

Output:

In this instance, the push_back method adds the additional elements to the vector v.

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