list empty() function in C++ STL Last Updated : 29 May, 2023 Comments Improve Suggest changes Like Article Like Report The list::empty() is a built-in function in C++ STL that is used to check whether a particular list container is empty or not. This function does not modify the list, it simply checks whether a list is empty or not, i.e. the size of the list is zero or not. Syntaxlist_name.empty() Parameters This function does not accept any parameter, it simply checks whether a list container is empty or not. Return Value The return type of this function is boolean.It returns True is the size of the list container is zero otherwise it returns False.Example The below program illustrates the list::empty() function. C++ // CPP program to illustrate the // list::empty() function #include <bits/stdc++.h> using namespace std; int main() { // Creating a list list<int> demoList; // check if list is empty if (demoList.empty()) cout << "Empty List\n"; else cout << "Not Empty\n"; // Add elements to the List demoList.push_back(10); demoList.push_back(20); demoList.push_back(30); demoList.push_back(40); // check again if list is empty if (demoList.empty()) cout << "Empty List\n"; else cout << "Not Empty\n"; return 0; } OutputEmpty List Not Empty Time Complexity: O(1)Space Complexity: O(1) Note: This function works in constant time complexity. Comment B barykrg Follow Improve B barykrg Follow Improve Article Tags : Misc C++ STL CPP-Functions cpp-list +1 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++ STL3 min readIterators in C++ STL10 min readC++ STL Algorithm Library3 min readPractice & ProblemsC++ Interview Questions and Answers1 min readC++ Programming Examples4 min read Like