How to write a program for swapping two strings without
using 3rd variable and without using string functions.
Answer Posted / gaurav rustagi
#include <iostream>
#include <string.h>
using namespace std;
void swap ( char ** , char ** ) ;
int main ()
{
char * buyer= "US Dollars" ;
char * seller = "IN Ruppees" ;
cout << "Before swap, buyer has " << buyer;
cout << " and seller has " << seller << endl;
swap (buyer,seller);
cout << " After swap, buyer has " << buyer;
cout << " and seller has " << seller << endl;
return 0;
}
void swap ( char ** L , char ** R )
{
char ** temp = R;
R = L ;
L = temp ;
}
| Is This Answer Correct ? | 7 Yes | 13 No |
Post New Answer View All Answers
What is the purpose of realloc()?
What are the rules for identifiers in c?
What are different types of variables in c?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
How do we make a global variable accessible across files? Explain the extern keyword?
WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?
What are loops in c?
What is meant by operator precedence?
can we implement multi-threads in c.
What is the difference between array and pointer in c?
What is auto keyword in c?
Where register variables are stored in c?
What are operators in c?
Are there namespaces in c?
Can the size of an array be declared at runtime?