How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / boomer
void Rstring( char *str,int len)
{
for(int i = 0; i < (len/2); i++)
{
str[i] ^= str[len-i-1];
str[len-i-1] ^= str[i];
str[i] ^= str[len-i-1];
}
}
int main( void )
{
char str[] = "my string";
printf("Actual string is [%s]\n", str);
Rstring(str,strlen(str));
printf("Reversed string is [%s]\n", str);
}
I dont call this swaping, coz it's not, recursive creates
new incarnations of the reverse func, EXTRA MEMORY BIG
TIME!!!
| Is This Answer Correct ? | 21 Yes | 40 No |
Post New Answer View All Answers
What is null pointer in c?
How can you draw circles in C?
When the macros gets expanded?
What is cohesion in c?
Tell me when would you use a pointer to a function?
In a switch statement, explain what will happen if a break statement is omitted?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What are loops c?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
Write a c program to demonstrate character and string constants?
Explain the advantages and disadvantages of macros.
How can I get the current date or time of day in a c program?
Why void is used in c?
Can we replace the struct function in tree syntax with a union?
Explain how can I remove the trailing spaces from a string?