array::size() in C++ STL
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.
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
Recommended Posts:
- Find the Deepest Node in a Binary Tree Using Queue STL - SET 2
- Lexicographical smallest alternate Array
- C++ program to compare two Strings using Operator Overloading
- not1 and not2 function templates in C++ STL with Examples
- Applications of Computer Graphics
- Go vs C++
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Trie Data Structure using smart pointer and OOP in C++
- Modular Exponentiation of Complex Numbers
- std::hash class in C++ STL
- Flat Panel Display
- Computer Animation
- History of C++
- What are Forward declarations in C++
- __builtin_inf() functions of GCC compiler
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



