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

Answer Posted / moinom

#include <iostream>
#include <conio>

void reverse(char a[], int s, int sc );

void reverse(char a[], int s, int sc ){

if ((sc-s)<(s-1))
{
a[sc-s]^=a[s-1];
a[s-1]^=a[sc-s];
a[sc-s]^=a[s-1];
reverse (a, s-1, sc) ;

}

}

void main (){


char a[]="ABCDEFG";

reverse(a, 7, 7);
cout<<a;
getch(); //i just use it to freeze the screen

}

Is This Answer Correct ?    14 Yes 29 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

hi friends how r u as soon in satyam my interview is start but i m very confusued ta wat i do plz help me frndz wat can i do plz tell me some question and answers related with "C" which r asked in the interview .

1895


what is a constant pointer in C

674


What is putchar() function?

633


What are the features of c languages?

624


How can I handle floating-point exceptions gracefully?

632






What are global variables and explain how do you declare them?

569


Is it possible to execute code even after the program exits the main() function?

807


what is ur strangth & weekness

1812


What happens if a header file is included twice?

584


What is the difference between scanf and fscanf?

660


Can a local variable be volatile in c?

573


What is wrong with this initialization?

585


What is the newline escape sequence?

581


A SIMPLE PROGRAM OF GRAPHICS AND THEIR OUTPUT I WANT SEE WAHAT OUTOUT OF GRAPHICS PROGRAM

1697


What are the key features in c programming language?

607