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

What is c standard library?

694


Why doesn't C support function overloading?

1624


Do you know null pointer?

616


How do we print only part of a string in c?

587


What is the use of sizeof () in c?

560






What should malloc() do? Return a null pointer or a pointer to 0 bytes?

628


how to write optimum code to divide a 50 digit number with a 25 digit number??

2757


When should the const modifier be used?

660


the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function

764


Can we change the value of static variable in c?

566


Explain threaded binary trees?

684


Explain what is operator promotion?

639


What is strcmp in c?

603


Explain what is #line used for?

610


What is difference between static and global variable in c?

541