Different methods to reverse a string in C/C++ - GeeksforGeeks

PHOTO EMBED

Fri Jun 18 2021 14:33:24 GMT+0000 (UTC)

Saved by @shourav_007 #c++

void reverseStr(string& str)
{
    int n = str.length();
 
    // Swap character starting from two
    // corners
    for (int i = 0; i < n / 2; i++)
        swap(str[i], str[n - i - 1]);
}
 
content_copyCOPY

https://www.geeksforgeeks.org/reverse-a-string-in-c-cpp-different-methods/