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


Please Help Members By Posting Answers For Below Questions

pgm to find number of words starting with capital letters in a file(additional memory usage not allowed)(if a word starting with capital also next letter in word is capital cann't be counted twice)

1872


How can I use a preprocessorif expression to ?

615


What is infinite loop?

638


i have to apply for the rbi for the post of officers. i need to know abt the entrance questions whether it may be aps or techinical....

1532


Write a program to print numbers from 1 to 100 without using loop in c?

653






All technical questions

1524


How many header files are in c?

562


What is the hardest programming language?

685


What is "Hungarian Notation"?

647


What is the general form of function in c?

620


What is the purpose of the statement: strcat (S2, S1)?

648


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

3739


Give differences between - new and malloc() , delete and free() ?

618


Why is c so popular?

664


What is the use of typedef in c?

597