Javatpoint Logo
Javatpoint Logo

C++ Vector swap()

This function is used to exchange the elements specified in two vectors.


Consider two vectors v1 and v2. Syntax would be:


v2: v2 is a vector, whose value is to be swapped with another vector.

Return value

It does not return any value.

Example 1

Let's see a simple example.


Before swapping,elements of v1 are :1 2 3 4 5 
Before swapping,elements of v2 are :6 7 8 9 10 
After swapping,elements of v1 are  :6 7 8 9 10 
After swapping,elements of v2 are :1 2 3 4 5

In this example, swap() function exchanges the elements of vector v1 with the vector v2.

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