Home » C++ Vector at() function

C++ Vector at() function

by Online Tutorials Library

C++ Vector at()

It gives a reference to an element.

Syntax

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

Parameter

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

Example

Let’s see a simple example.

Output:

1234 

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

Next TopicC++ Vector

You may also like