vector empty() in C++

empty(): It returns true if the vector is empty , otherwise returns false.

If vector is empty then, begin() == end().

Parameters: Their is no parameter for this function.

Syntax:

vecName.empty()

For Example:

vec = {1,2,3,4}

vec.empty() => It returns false.

vec = {}

vec.empty() = > It returns true

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<intvec = {1234};

    if (vec.empty())
        cout << "Vector is empty\n";
    else
        cout << "Vector is not empty\n";

    return 0;
}


No comments:

Post a Comment