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

The array::size() is a C++ Standard Library function which is used to get the size of the array.

Syntax:

Array_Name.size();

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

Return value: The array::size() function returns the size of the array.

Example of array::size() Function

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

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

	return 0;
}

Output

size of Array_1: 0
size of Array_2: 3
size of Array_3: 4
size of Array_4: 5

This article is written by

Shubham Singh

Shubham Singh

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"]