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
What is a structure and why it is used?
How can you increase the size of a dynamically allocated array?
What is pointers in c?
why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above
Is there anything like an ifdef for typedefs?
Explain how do you generate random numbers in c?
How is actual parameter different from the formal parameter?
What Is The Difference Between Null And Void Pointer?
Can variables be declared anywhere in c?
What is #define in c?
What are the scope of static variables?
What is difference between array and structure in c?
How can I discover how many arguments a function was actually called with?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
How do I swap bytes?