Reverse string without using any temporary variable | C ++ Program to reverse a string without using temp variable ; Function to reverse string and return revesed string ; Iterate loop upto start not equal to end ; XOR for swapping the variable ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string reversingString ( string str , int start , int end ) { while ( start < end ) { str [ start ] ^= str [ end ] ; str [ end ] ^= str [ start ] ; str [ start ] ^= str [ end ] ; ++ start ; -- end ; } return str ; } int main ( ) { string s = " GeeksforGeeks " ; cout << reversingString ( s , 0 , 12 ) ; return 0 ; }