Vector Empty Function - C++ Programming Tutorial
C++ Course / STL Vector / Vector Empty Function

Vector Empty Function

BLUF: Mastering Vector Empty Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Vector Empty Function

C++ is renowned for its efficiency. Learn how Vector Empty Function enables low-level control and high-performance computing in the tutorial below.

C Vector empty

This function checks if the vector is empty or not.

Syntax

Consider a vector v. Syntax would be :

Example

bool empty();

Parameter

It does not contain any parameter.

Return value

It returns a boolean value either 0 or 1.

Example 1

Let's see a simple example.

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:

Output

Vector v is empty

Example 2

Let's see a simple example.

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:

Output

Vector v1 is not empty.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience