![]() |
In C++, vectors in C++ are dynamic arrays that can grow or shrink in size as elements are added or removed. In this article, we will learn how to find the size of a vector in C++. Example Input: myVector = {1, 2, 3, 4, 5, 6, 7, 8} Find the Size of the Vector in C++In C++, the vector contains keep track of their size themselves. We can simply use the std::vector::size() member function of the std::vector class to get the size of the vector container. It returns the size i.e. number of elements present in the vector in the form of an integer. C++ Program to Find the Size of the VectorC++
Output
Vector: 1 2 3 4 5 6 7 8 Size of the Vector: 8 Time complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |