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 a #include preprocessor?

849


a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f

1866


Place the #include statement must be written in the program?

787


What functions are in conio h?

923


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

2024


Explain the use of bit fieild.

939


Why we write conio h in c?

779


Does c have an equivalent to pascals with statement?

796


How can I make it pause before closing the program output window?

825


How does sizeof know array size?

867


How can I do serial ("comm") port I/O?

944


what is reason of your company position's in india no. 1.

1994


What is c standard library?

942


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

1069


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

2557