English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++ The List empty() function checks if the list is empty. If the list is empty, it returns true; otherwise, it returns false. It does not modify the content of the list.
bool empty();
It does not contain any parameters.
It returns a boolean value1or 0. If the list is empty, it returns1otherwise returns 0.
Let's look at a simple example when the list is empty.
#include <iostream> #include<list> using namespace std; int main() { list<int> li; std::cout << "empty() : " << li.empty() << std::endl; return 0; }
Output:
empty() : 1
In this example, the return value of the empty() function is1because the list 'li' is empty.
Let's see a simple example when the list is not empty.
#include <iostream> #include<list> using namespace std; int main() { list<int> li={1,2,3}; std::cout << "empty() : " << li.empty() << std::endl; return 0; }
Output:
empty() : 0
In this example, since the list is not empty, the empty() function returns the value '0'.