Javatpoint Logo
Javatpoint Logo

C++ Vector at()

It gives a reference to an element.


Consider a vector v and k is the position. Syntax would be:


k: k defines the position of element which is to be returned by at() function.

Return value

It returns the element of specified position.

The following illustration shows how at() function works

If i=0 :

cpp vector at() function

If i=3 :

cpp vector at() function


Let's see a simple example.



In this example, at() function access the elements of vector .

Next TopicC++ Vector

Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials

B.Tech / MCA