How to reverse a string using a recursive function, without
swapping or using an extra memory?

Answer Posted / prakash

#include <stdio.h>

void reverse(char *str)
{
if (*str == '\0')
return;

reverse(str+1);

printf("%c", *str);
}

int main()
{
char str[50];

printf("Enter the string: ");
scanf("%s", str);

printf("Reversed string: ");
reverse(str);
printf("\n");

return 1;
}

Is This Answer Correct ?    23 Yes 24 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the best way of making my program efficient?

774


What is the correct code to have following output in c using nested for loop?

841


In which layer of the network datastructure format change is done

1644


How would you rename a function in C?

813


What is difference between function overloading and operator overloading?

871


What is static identifier?

918


What is conio h in c?

814


Define macros.

1031


What is the difference between text and binary i/o?

782


Process by which one bit pattern in to another by bit wise operation is?

860


Why main function is special give two reasons?

1222


What is exit() function?

771


Why c is called procedure oriented language?

805


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

852


Write a program to use switch statement.

891