English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ Usage and examples of List max_size()

C++ List (List)

C ++ The List max_size() function determines the maximum size of the list. This function does not change the size of the list.

Syntax

size_type max_size();

Parameters

It does not contain any parameters.

Return value

It returns the maximum number of elements that the list can contain.

Example

Let's see a simple example

#include<iostream>
#include<list>
using namespace std;
int main()
{
    list<int> li={9,10,11
    std::cout << "The size of the list is: " << li.max_size() << std::endl;
    return 0;

Output:

The size of the list is: 357913941

In this example, the max_size() function returns the maximum size that the list can accommodate.

C++ List (List)