![]() |
VOOZH | about |
In C++, the std::stack::top() is used to find the top element of the std::stack container. It is a member function of std::stack class defined inside the <stack> header file. In this article, we will learn how to find the top element of stack using stack::top() in C++.
Example:
11 9
st.top()
where st is the name of std::stack.
The following examples demonstrates the use of stack::top() function in different scenarios:
9 11
Output
Undefined behaviour