How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / right
char* reverseStringR(char* string){
if(string[0] && !string[1])
return string;
char first = string[0];
reverseStringR(string+1);
size_t length_rest = strlen(string+1);
memmove(string, string+1, length_rest);
string[length_rest] = first;
return string;
}
| Is This Answer Correct ? | 3 Yes | 4 No |
Post New Answer View All Answers
Why should I use standard library functions instead of writing my own?
Does c have function or method?
Why is c so popular?
What is #include stdlib h?
What is an lvalue in c?
What is advantage of pointer in c?
What is substring in c?
How would you use the functions fseek(), freed(), fwrite() and ftell()?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
Is c++ based on c?
Why c is a procedural language?
What does == mean in texting?
What does %c do in c?
Is c is a procedural language?
What is c language used for?