array::empty() function in C++ STL

The array::empty() is a C++ Standard Library function which is used to check whether an array is empty or not and returns the 1 for empty array or 0 for non empty array. example

Syntax

Array_Name.empty();

Parameter: The array::empty() function does not accepts any parameters.

Return value: The array::empty() function returns the 1(true) for empty array or 0(false) for non empty array.

Example Program For array::empty() in STL

#include <iostream>
#include <array>
using namespace std;

int main() {
    
	array<int,0> Array_1{};  
	cout<<"Is Array_1 empty ? : "<<Array_1.empty()<<endl;
	
	array<int,3> Array_2{};   
	cout<<"Is Array_2 empty ? : "<<Array_2.empty()<<endl;
	
	array<int,4> Array_3{1, 2, 3};     
	cout<<"Is Array_3 empty ? : "<<Array_3.empty()<<endl;
	
	array<int,5> Array_4{1, 2, 3, 4, 5};
	cout<<"Is Array_4 empty ? : "<<Array_4.empty()<<endl;

	return 0;
}

This article is written by

Pratik Singhal

Pratik Singhal

Please comment below, if you have any doubts or find any error in the above article.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
[gravityforms id="5" description="false" titla="false" ajax="true"]