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 NULL pointer?
Do you know the purpose of 'register' keyword?
Why c is called object oriented language?
What are integer variable, floating-point variable and character variable?
What are operators in c?
What is stack in c?
Are bit fields portable?
What is the difference between a function and a method in c?
Why functions are used in c?
Should a function contain a return statement if it does not return a value?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
Is that possible to add pointers to each other?
What is the most efficient way to store flag values?
What are dangling pointers? How are dangling pointers different from memory leaks?
How many bytes is a struct in c?