Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / rafael christ

#include <iostream>


using namespace std;


char* reverse_str(char* s)
{
char* reverse = new char[1];
//char* reverse;


int i;

if(*s != '\0')
reverse = reverse_str(s+1);

i = strlen(s) - 1;

if (i >= 0)
reverse[i] = s[0];

return reverse;
}


int main(void)
{
char* str = "tsirhc oraivur odraude leafar";


cout << "original:" << endl;
cout << str << endl << endl;

cout << "reversed:" << endl;
cout << reverse_str(str) << endl;

return 0;
}

Is This Answer Correct ?    14 Yes 25 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

1143


What is the difference between printf and scanf in c?

1359


Which is better oop or procedural?

1071


write a program to display all prime numbers

1972


What happens if header file is included twice?

1152


Write a C program in Fibonacci series.

1092


What is array in C

1165


What is sizeof int?

1105


Write a program to generate random numbers in c?

1103


What are inbuilt functions in c?

1037


Why is C language being considered a middle level language?

1130


What is the difference between test design and test case design?

2093


What is structure of c program?

1168


What is quick sort in c?

1093


What are the functions to open and close the file in c language?

1041