Javatpoint Logo
Javatpoint Logo

C++ String swap()

This function is used to exchange the values of two string objects.


Consider two strings s1 and s2 , we want to exchange the values of these two string objects. Its syntax would be :


It contains single parameter, whose value is to be exchanged with that of the string object.

Return value

It does not return any value.

Example 1


Before  swap  r  contains 10 rupees
Before  swap  m contains 20 rupees
After  swap r contains 20 rupees
After swap m contains 10 rupees

In this example, r and m are two string objects containing 10 and 20 rupees respectively. We swap there values by using swap function. After swapping, r contains 20 rupees and m contains 10 rupees.

Next TopicC++ Strings

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA