stack::pop() 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::pop() is a C++ Standard Library function which is used to remove an element from the top of the stack. After removing the element to the stack container the size decreased by 1.

Syntax

Stack_Name.pop( );

Parameter: The stack::pop() function does not accepts any parameter.

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

Example of stack::pop() Function

#include <iostream> 
#include <stack> 
using namespace std; 
  
int main() 
{ 
    stack<int> STK;
    
    STK.push(10);
    
    STK.push(20); 
    
    STK.push(30); 
  
    while (!STK.empty()) 
    { 
        cout << STK.top() << ' '; 
        STK.pop(); 
    } 
} 

Output

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