![]() |
In C++, the vector is a dynamic array that can resize itself automatically to accommodate new elements. In this article, we will learn how to declare a vector in C++. Declare a Vector in C++In C++, vectors are defined as the class templates in <vector> header file. So, to declare a std::vector in C++, we first need to include the <vector> header. Then, we can declare a vector variable or object or instance using the below syntax Syntax to Declare Vector in C++vector<dataType> vector_Name; Here,
The above vector will be constructed using the default constructor. We can also create a vector with different constructors as shown here. C++ Program to Declare a VectorThe following program illustrates how we can declare a vector in C++:
Output Vector Elements: 1 2 3 4 5 Time Complexity: O(N) where N is the size of the vector. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |