How to Check if a Stack is Empty in C++? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report In C++, we have a stack data structure that follows a LIFO (Last In First Out) rule of operation. In this article, we will learn how to check if a stack is empty in C++. Example:Input:myStack = {1, 2, 3 } Output:Stack is not EmptyChecking if a Stack is Empty in C++To check if a stack is empty in C++, we can use the std::stack::empty() function that returns a boolean value true if the stack is empty and false if the stack is not empty. C++ Program to Check if a Stack is EmptyThe below example demonstrates how we can check if a given stack is empty or not in C++ STL. C++ // C++ program to illustrate how to check if a stack is // empty #include <iostream> #include <stack> using namespace std; int main() { // Creating a stack stack<int> mystack; // Checking if stack is empty if (mystack.empty()) cout << "Stack is empty\n"; else cout << "Stack is not empty\n"; // Adding elements to the stack mystack.push(10); mystack.push(20); mystack.push(30); // Again Checking if stack is empty if (mystack.empty()) cout << "After Updation Stack is empty\n"; else cout << "After Updation Stack is not empty\n"; return 0; } OutputStack is empty After Updation Stack is not empty Time Complexity: O(1)Auxiliary Space: O(1) Create Quiz Comment G gauravgandal Follow 1 Improve G gauravgandal Follow 1 Improve Article Tags : C++ Programs C++ STL cpp-stack cpp-stack-functions CPP Examples +2 More Explore C++ BasicsIntroduction to C++3 min readData Types in C++6 min readVariables in C++4 min readOperators in C++9 min readBasic Input / Output in C++3 min readControl flow statements in Programming15+ min readLoops in C++7 min readFunctions in C++8 min readArrays in C++8 min readCore ConceptsPointers and References in C++5 min readnew and delete Operators in C++ For Dynamic Memory5 min readTemplates in C++8 min readStructures, Unions and Enumerations in C++3 min readException Handling in C++12 min readFile Handling in C++8 min readMultithreading in C++8 min readNamespace in C++5 min readOOP in C++Object Oriented Programming in C++8 min readInheritance in C++6 min readPolymorphism in C++5 min readEncapsulation in C++3 min readAbstraction in C++4 min readStandard Template Library(STL)Standard Template Library (STL) in C++3 min readContainers in C++ STL2 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like