Skip to content
Related Articles

Related Articles

deque max_size() function in C++ STL
  • Last Updated : 30 Jul, 2018

The deque::max_size() is a built-in function in C++ STL which returns the maximum number of elements that a deque container can hold.

Syntax:

deque_name.max_size()

Parameters: The function does not accept any parameters.

Return Value: The function returns the maximum number of elements that a deque container can hold.

Below programs illustrate the above function:



Program 1:




// CPP program to demonstrate the
// deque::max_size() function
// when deque is non-empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    deque<int> dq;
  
    dq.push_back(1);
    dq.push_back(10);
    dq.push_back(100);
    dq.push_back(50);
    dq.push_back(40);
    dq.push_back(23);
    dq.push_back(6);
  
    cout << "The deque elements: ";
    for (auto it = dq.begin(); it != dq.end(); it++)
        cout << *it << " ";
  
    cout << "\nThe max-size of deque: " << dq.max_size();
  
    return 0;
}


Output:

The deque elements: 1 10 100 50 40 23 6 
The max-size of deque: 4611686018427387903

Program 2:




// CPP program to demonstrate the
// deque::max_size() function
// when deque is empty
#include <bits/stdc++.h>
using namespace std;
int main()
{
    deque<int> dq;
  
    cout << "The max-size of deque: " << dq.max_size();
  
    return 0;
}


Output:

The max-size of deque: 4611686018427387903

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :