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


Please Help Members By Posting Answers For Below Questions

How variables are declared in c?

569


Where register variables are stored in c?

546


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

15491


What is the use of structure padding in c?

561


Where static variables are stored in memory in c?

521






What is difference between structure and union?

593


What does the error message "DGROUP exceeds 64K" mean?

725


what is the diffrenet bettwen HTTP and internet protocol

1383


Which is better malloc or calloc?

645


Is exit(status) truly equivalent to returning the same status from main?

583


Why double pointer is used in c?

563


What are the application of void data type in c?

697


What is a good way to implement complex numbers in c?

591


What are reserved words with a programming language?

599


Is c a great language, or what?

600