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
What are the types of arrays in c?
What is the difference between printf and scanf )?
#include
What is the benefit of using const for declaring constants?
What is a union?
Why do some versions of toupper act strangely if given an upper-case letter?
Explain what happens if you free a pointer twice?
What are the c keywords?
What is use of pointer?
What is volatile keyword in c?
What is a ternary operator in c?
Is c procedural or object oriented?
Why main function is special give two reasons?
.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }
Explain what are the different data types in c?