Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

array::size() in C++ STL

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article


Array classes are generally more efficient, light-weight and reliable than C-style arrays. The introduction of array class from C++11 has offered a better alternative for C-style arrays.

array::size()

size() function is used to return the size of the list container or the number of elements in the list container.

Syntax :

arrayname.size()
Parameters :
No parameters are passed.
Returns :
Number of elements in the container.

Examples:

Input  : myarray{1, 2, 3, 4, 5};
         myarray.size();
Output : 5

Input  : myarray{};
         myarray.size();
Output : 0

Errors and Exceptions

1. It has a no exception throw guarantee.
2. Shows error when a parameter is passed.




// CPP program to illustrate
// Implementation of size() function
#include <iostream>
#include <array>
using namespace std;
  
int main()
{
    array<int,5> myarray{ 1, 2, 3, 4, 5 };
    cout << myarray.size();
    return 0;
}

Output:

5
My Personal Notes arrow_drop_up
Last Updated : 15 Jan, 2018
Like Article
Save Article
Similar Reads
Related Tutorials