array::max_size() function with Example in C++ STL

C++ STL | array::max_size() function: Here, we are going to learn about the max_size() function of Array in C++ STL.
Submitted by IncludeHelp, on March 01, 2019

C++ STL array::max_size() function

max_size() function is a library function of array and it is used to get maximum size of an array. It returns the total number of elements that an array can hold.

Syntax:

    array_name.max_size();

Parameters: None

Return value: Total number of elements that an array can hold.

Example:

    Input or array declaration:
    array<int,5> values {10, 20, 30, 40, 50};

    Function call:
    values.max_size();

    Output:
    5

C++ STL program to get the maximum number of elements that an array can hold using array:max_size()

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

int main()
{
	array<int,5> arr1 {10, 20, 30, 40, 50};
	array<int,10> arr2 {10, 20, 30};
	array<int,0> arr3; //array of 0 size
    
	//printing size of arrays
	cout<<"size of arr1: "<<arr1.max_size()<<endl;
	cout<<"size of arr2: "<<arr2.max_size()<<endl;
	cout<<"size of arr3: "<<arr3.max_size()<<endl;

	return 0;
}

Output

size of arr1: 5
size of arr2: 10
size of arr3: 0

Ref: std::array::max_size()


ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.