VOOZH about

URL: https://www.geeksforgeeks.org/cpp/list-push_back-function-in-c-stl/

⇱ list push_back() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

list push_back() function in C++ STL

Last Updated : 30 May, 2023

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.

Syntax

list_name.push_back(value)

Parameters

  • 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.

Example

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


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

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

Comment
Article Tags: