List Push Back Function - C++ Programming Tutorial
C++ Course / Dynamic Programming / List Push Back Function

List Push Back Function

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

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

C++ List push_back

Adding a new element at the end of a C++ list is achieved by using the push_back method, which results in an increment of the list container's size by one.

The push_back method adds the element 5 to the back of the container.

Syntax

Suppose a element is 'x':

Example

push_back(const value_type& x);

Parameter

x : It is the value to be inserted at the end.

Return value

It does not return any value.

Example 1

Let's see a simple example

Example

#include <iostream>
#include<list>
using namespace std;

int main()
{
   list<string> li={"C"," C++"," .Net"};
   list<string>::iterator itr;
   li.push_back(" java");
   li.push_back(" PHP");
  for(itr=li.begin();itr!=li.end();++itr)
   cout<<*itr;
    return 0;
}

Output:

Output

C  C++  .Net java PHP

In this instance, the push_back method appends two strings, namely Java and PHP, to the end of the list.

Example 2

Let's see a simple example

Example

#include <iostream>
#include<list>
using namespace std;
int main()
{
   list<int> li={6,7,8,9};
   list<int>::iterator itr;
   li.push_back(10);
   li.push_back(11);
  for(itr=li.begin();itr!=li.end();++itr)
   cout<<*itr<<","
   return 0;
}

Output:

Output

6,7,8,9,10,11

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