C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C Vector empty()This function determines whether the vector is empty or not. Syntax
Consider a vector v. Syntax would be : bool empty(); Parameter
It does not contain any parameter. Return valueIt returns a boolean value either 0 or 1. Example 1
Let's see a simple example.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> v;
if(v.empty())
cout<<"Vector v is empty";
else
cout<<"Vector v is not empty";
return 0;
}
Output: Vector v is empty Example 2Let's see a simple example.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<char> v1{'j','a','v','a'};
if(v1.empty())
cout<<"Vector v1 is empty";
else
cout<<"Vector v1 is not empty";
return 0;
}
Output: Vector v1 is not empty.
Next TopicC++ Vector
|