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 / smbrd

&#65279;#include <iostream>

using namespace std;

void rev_str(char* str, int pos=-1, char c='\0'){
if(pos >= int(strlen(str)/2))
return;
if(c != '\0'){
str[strlen(str) - pos - 1] = str[pos];
str[pos] = c;
}
rev_str(str, ++pos, str[strlen(str) - pos - 2]);
}

int main(){
char str[] = "reverse this string";
cout << str << endl;
rev_str(str);
cout << str << endl;
//:~
return 0;
}

Is This Answer Correct ?    7 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of bitwise operator?

1118


GIVEN A FLOATING POINT NUMBER HOW IS IT ACTUALLY STORED IN MEMORY ? CAN ANYONE EXPLAIN?? THE 32 BIT REPRESENTATION OF A FLOATING POINT NUMBER ALLOTS: 1 BIT-SIGN 8 BITS-EXPONENT 23 BITS-MANTISSA

1880


Why cant I open a file by its explicit path?

1040


What is difference between scanf and gets?

1288


Write a program to show the change in position of a cursor using c

1075


What is local and global variable in c?

1212


What is call by reference in functions?

1463


Explain why c is faster than c++?

1080


What is conio h in c?

1049


What do you understand by friend-functions? How are they used?

1213


What does emoji p mean?

1127


What is the difference between null pointer and wild pointer?

1204


What does the error 'Null Pointer Assignment' mean and what causes this error?

1231


What is putchar() function?

1170


What are the types of type qualifiers in c?

1093