![]() |
In C++, vector containers are dynamic arrays that can adjust their size automatically according to the number of elements they are storing. In this article, we will see how to get the element in a vector using the specified position in C++ Example Input: Access an Element in a Vector using an Index in C++Similar to arrays, vectors also follow the 0-based indexing in C++, where the index starts from 0 and goes till n-1 where n is the total number of elements in the vector. ![]() Vector Indexing We can use the array subscript operator [] with the index value inside them to access the vector element in C++ in a similar way to arrays. C++ Program Access an Element in a Vector using an IndexC++
Output
Vector: 10 20 30 40 50 60 70 Element at index 4 is: 50 Time Complexity : O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |