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


Please Help Members By Posting Answers For Below Questions

Can we declare variables anywhere in c?

774


Where static variables are stored in c?

796


What is the role of this pointer?

766


What is void c?

780


Why is c so powerful?

885


What is a global variable in c?

780


How can I change their mode to binary?

904


What is a memory leak? How to avoid it?

891


Explain the red-black trees?

827


What are the types of arrays in c?

859


How can I remove the trailing spaces from a string?

828


What is union in c?

853


How can I run c program?

939


What is %s and %d in c?

764


How do we make a global variable accessible across files? Explain the extern keyword?

1642