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

C++ Usage and example of List size()

C++ List (List)

C ++ The List size() function finds the number of existing elements in the list. This function does not modify the content of the deque.

Syntax

int size();

Parameter

It does not contain any parameters.

Return Value

It returns the number of elements in the list.

Example

Let's see a simple example

#include <iostream>
#include<list>
using namespace std;
int main()
{
    list<int> li={1,2,3};
    std::cout << "The size of the list is: " << li.size() << std::endl;
    return 0;
{}

Output:

The size of the list is: 3

In this example, the size() function returns the size of the list, that is3.

C++ List (List)