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

how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1715


a c code by using memory allocation for add ,multiply of sprase matrixes

2561


how do you execute a c program in unix.

883


Hai what is the different types of versions and their differences

1748


What is table lookup in c?

863


How can you increase the size of a dynamically allocated array?

939


Explain can you assign a different address to an array tag?

875


What does 3 periods mean in texting?

844


What are the usage of pointer in c?

938


what is the height of tree if leaf node is at level 3. please explain

1864


How can you restore a redirected standard stream?

822


What does the && operator do in a program code?

974


What is dynamic memory allocation?

1093


What are register variables in c?

828


What is int main () in c?

891