Open In App
Related Articles

list push_back() function in C++ STL

Improve Article
Save Article
Like Article

The list:push_back() function in C++ STL is used to add a new element to an existing list container. It takes the element to be added as a parameter and adds it to the list container.




  • This function accepts a single parameter which is a mandatory value. This refers to the elements needed to be added to the list, list_name.

Return Value

  • The return type of this function is void and it does not return any value.


The below program illustrates the list::push_back() function.


// CPP program to illustrate the
// list::push_back() function
#include <bits/stdc++.h>
using namespace std;
int main()
    // Initialization of list
    list<int> demo_list;
    // initial size of list
    cout << "Initial Size of the list: " << demo_list.size()
         << endl;
    // Adding elements to the list
    // using push_back function
    // Size of list after adding
    // some elements
    cout << "Size of list after adding three "
         << "elements: " << demo_list.size();
    return 0;


Initial Size of the list: 0
Size of list after adding three elements: 3

Time Complexity: O(1)
Auxiliary Space: O(1)

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 May, 2023
Like Article
Save Article
Similar Reads