How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / pritam
/*
reverse string between start and end indexes of a string
*/
void reverse( char* str, int start, int end )
{
if( str && ( start < end ) )
{
*( str + start ) ^= *( str + end ) ^= *( str + start )
^= *( str + end ) ;
reverse( str, ++start, --end );
}
}
int main()
{
char sample[] = "My String!";
reverse( str, 0, strlen( sample )-1 )
}
Is This Answer Correct ? | 15 Yes | 17 No |
Post New Answer View All Answers
Can we declare variables anywhere in c?
Where static variables are stored in c?
What is the role of this pointer?
What is void c?
Why is c so powerful?
What is a global variable in c?
How can I change their mode to binary?
What is a memory leak? How to avoid it?
Explain the red-black trees?
What are the types of arrays in c?
How can I remove the trailing spaces from a string?
What is union in c?
How can I run c program?
What is %s and %d in c?
How do we make a global variable accessible across files? Explain the extern keyword?