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

C++ STL map::max_size() function with example: Here, we are going to learn about the map::max_size() function in C++ STL, that is used to return the maximum number of elements of the map that it can store.
Submitted by Vivek Kothari, on December 03, 2018

C++ STL map::max_size()

It returns the maximum number of elements the container(map) is able to hold but at runtime, the size of the container may be limited to a value smaller than specified by max_size() by the amount of RAM available. It gives us an only a theoretical limit on the size of the container.



Where, myMap is the object of class map.

Parameters: None - It does not accept any parameters.

Return value: It simply returns the maximum number of elements container can hold.


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

int main() 
	// create map container 
	map<int, int> myMap;

	//insert an element in map
	myMap.insert( pair<int, int>(200 , 100) ); 

	cout<<"max size of Non-empty map : \n"; 
	cout << "The max size of myMap is " << myMap.max_size();

	map<char,char> EmpMap;
	map<int, int> EmpMap2; 

	cout<<"max size of Empty-map : \n"; 
	cout << "\nThe max size of EmpMap is " << EmpMap.max_size();
	cout << "\nThe max size of EmpMap2 is " << EmpMap2.max_size();

	return 0; 


max size of Non-empty map :
The max size of myMap is 461168601842738790max size of Empty-map :

The max size of EmpMap is 461168601842738790
The max size of EmpMap2 is 461168601842738790


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

© some rights reserved.