Javatpoint Logo
Javatpoint Logo

C++ Vector operator[]()

This function is used to access a specified element.


Consider a vector 'v' and position 'pos'. Syntax would be:


pos: It defines the position of the element.

Return value

It returns the element of specified location.

Example 1

Let's see a simple example.


C C++ java

In this example,each element is accessd using operator[]() function.

Example 2

Let's see simple example


1 2 3 4 5

In this example, each element of vector v is accessed using operator[] () function.

Next TopicC++ Vector

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA