View algorithms on Strings
Question:How will you swap two strings in C? Let us consider the below program. Output of the program is str1 is study, str2 is algorithms. So the above swap() function doesn’t swap strings. The function just changes local pointer variables and the changes are not reflected outside the function. Let us see the correct ways for swapping strings: Method 1(Swap Pointers):- If you are using character pointer for strings (not arrays) then change str1 and str2 to point each other’s data. i.e., swap pointers. In a function, if we want…