Javatpoint Logo
Javatpoint Logo

C++ Vector swap()

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

Syntax

Consider two vectors v1 and v2. Syntax would be:

Parameter

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.

Output:

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




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA