stack::push() function in C++ STL

In C++, the standard library gives us the facility to use the Stacks as a type of container adaptors with LIFO type of working. The stack::push() is a C++ Standard Library function which is used to insert an element at the top of the stack. After adding the element to the stack container the size increased by 1.


Stack_Name.push( Value );

Parameter: The stack::push() function accepts only a single parameter:

  • Value: This parameter is the value of the element to be added to the Stack.

Return value: The stack::push() function does not returns any value.

Example of stack::push() Function

#include <iostream> 
#include <stack> 
using namespace std; 
int main() 
    stack<int> STK;
    while (!STK.empty()) 
        cout << << ' '; 


30 20 10 

This article is written by

Pratik Singhal

Pratik Singhal

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]