How to Add an Element at the End of List in C++? Last Updated : 27 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, the Standard Template Library (STL) has a doubly-linked list container, known as std::list that offers various functions to manipulate elements. In this article, we will learn how to add an element at the end of a list in C++ STL. Example: Input: myList = {1, 2, 3}; Output: List after Element Added: 1 2 3 4Add an Element at the End of the List in C++To add an element at the end of a std::list in C++, we can use the std::list::push_back() method that inserts the element at the end of the list, increasing its size by one. We just need to pass the value to be added as an argument. Syntax to Add an Element at the End of a List in C++list_name.push_back(value)Here, list_name denotes the name of the list where the element will be added.value is the element that will be added to the end of the list.C++ Program to Add an Element at the End of a ListThe below example demonstrates how we can use the push_back() function to add an element at the end of a list in C++. C++ // C++ Program to illustrate how to add an element at the // end of a list #include <iostream> #include <list> using namespace std; int main() { // Creating a list list<int> myList = { 1, 2, 3 }; // Printing the original list cout << "Original List:"; for (int num : myList) { cout << " " << num; } cout << endl; // Adding an element at the end of the list myList.push_back(4); // Printing the list after adding the element cout << "List after Element Added:"; for (int num : myList) { cout << " " << num; } cout << endl; return 0; } OutputOriginal List: 1 2 3 List after Element Added: 1 2 3 4 Time Complexity: O(1)Auxilary Space: O(1) Comment More infoAdvertise with us Next Article How to Add an Element at the End of List in C++? G gauravgandal Follow Improve Article Tags : C++ Programs C++ STL cpp-list CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Add an Element at the Front of a List in C++? In C++, the STL has a doubly linked list container defined as the std::list class template inside the <list> header. It stores the sequential data in non-contiguous memory locations. In this article, we will learn how to add an element at the beginning of a list in C++ STL. Example: Input: myL 2 min read How to Add an Element at the End of a Deque in C++? In C++, a deque is a flexible data structure that supports the insertion and deletion of elements from both ends efficiently. In this article, we will learn how to add an element at the end of a deque in C++. Example: Input: myDeque ={10,20,30,40} Output: // added element 50 at the end myDeque ={10, 2 min read How to Remove an Element from the End of a List in C++? In C++, lists are data structures that allow us to store data of the same type in non-contiguous memory locations. In this article, we will learn how to remove an element from the end of a list in C++. Example Input: myList={10,20,30,40,50} Output: List Elements: 10 20 30 40Delete the Last Element f 2 min read How to Add Multiple Elements at the End of Vector in C++? In C++, vectors are dynamic arrays that can grow and reduce in size as per requirements. In this article, we will learn how to add multiple elements at the end of a vector in C++. Example Input:myVector = {10, 20, 30, 40, 50}elements_to_add = {60, 70, 80}Output:updated_vector: 10 20 30 40 50 60 70 8 2 min read How to Add Element at the End of a Vector in C++? Vector allows fast insertion and deletion at the end. In this article, we will learn different ways to add an element at the end of the vector.The easiest way to add an element at the end of vector is by using vector push_back() function. Letâs take a look at a simple example:C++#include <bits/st 4 min read Like