 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you how you can swap values of two strings using call by reference method in C++. Before starting, you can subscribe my YouTube channel by clicking on the link which is available at bottom right corner of this video. You can download my app Takimis that is available on Google Play. You can connect with me by following these details which are available in front of you. Now coming onto the code, first statement is a comment which is showing swapping two strings using call by reference method in C++. Then I have included two header files IOStream and String. Then a namespace is used which is std. It is available in IOStream header file and it is for seen and see out. Then a class String is defined. In this class, I have declared an attribute of character type which is an array name is str. Then in public section, three functions are declared void read void print and void swap. Swap function will be receiving an argument of string type. Then I have terminated the class. After termination of class, I have defined read function. So void is return type here string is name of class then scope resolution operator then read is name of function. Inside this function, see out will display enter a string as is and handle is for line termination. It's full form is and line. Using seen, I am reading values inside str array. Then second function print is defined void is again return type here then string is name of class then scope resolution operator then print is name of function. Inside it see out will display string is equals to as it is then str variables value and handle will change the cursor position into new line. After that, I have implemented two more functions swap and main swap is part of class. So void string scope resolution swap then argument is received inside as this ampersand is showing that s is a reference variable. So this function is implemented using call by reference method and s is formal argument here then string temporary object is created here. Now I am using str cp back for copying values. So str is copied into temp.str then s.str is copied into str then temp.str is copied into s.str. So wherever I am using simple str is representing implicit argument and s.str is representing explicit argument. So this you can understand using main function in main. I have declared two objects s1 and s2 s1 is read using s1 dot read function similar to s1 s2 dot read function is also called then s1 dot swap s2 this statement is calling swap function here s1 is implicit argument and s2 is explicit argument. So s2 will be passed inside this s formal parameter and s is a reference variable. So this s will be sharing memory of s2 object that is passed explicitly from the main function. And this s1 is passed implicitly so you can use this directly here. So I have also commented that str wherever we are using is representing implicit argument that is s1 and s.str is representing explicit argument that is s2 here and s2 is shared by s that's why we are using it using s.str and temp is temporary object which is used for swapping purpose. So str which is representing implicit first it is assigning into temporary object then explicit is assigning into implicit and then temporary is again assigning into explicit this way all the elements are swapped then s1 dot print and s2 dot print functions are called. Now I am executing this code it is asking for first string I am entering Sanjay second string Gupta you can see that string one is Gupta and string two is Sanjay. So values of s1 and s2 are swapped here with the help of call by reference method. If I remove this call by reference method from here now see the effect I have to remove it from here also. If I remove call by reference method then you can see both the strings are printing same results. So friends if you want to change both the arguments implicit as well as explicit then instead of call by value you have to prefer call by reference method as I have removed m percent sign then this method has converted into call by value method. So I hope you have understood how you can swap values of two strings using call by reference method in C++. If you want to watch more programming related videos you can subscribe my YouTube channel that is sanjaygupta underscore tech school. Thank you for watching this video.