C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
C++ Vector at()It gives a reference to an element. SyntaxConsider a vector v and k is the position. Syntax would be: vector<object_type> v; v.at(k) ; Parameterk: k defines the position of element which is to be returned by at() function. Return valueIt returns the element of specified position. The following illustration shows how at() function worksIf i=0 : If i=3 : ExampleLet's see a simple example. #include<iostream> #include<vector> using namespace std; int main() { vector<int> v1{1,2,3,4}; for(int i=0;i<v1.size();i++) cout<<v1.at(i); return 0; } Output: 1234 In this example, at() function access the elements of vector .
Next TopicC++ Vector
|