How to write a program for swapping two strings without
using 3rd variable and without using string functions.
Answers were Sorted based on User's Feedback
Answer / sivaraj
Questions is to swap the string not for integers so the
above answers are wrong.
| Is This Answer Correct ? | 47 Yes | 7 No |
Answer / 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 |
Answer / sri
main()
{
int a=5,b=3;
a=a+b;
b=a-b;
a=a-b;
printf(" %d %d ",a,b);
getch();
}
| Is This Answer Correct ? | 33 Yes | 42 No |
Answer / biswambar
main()
{
int a=5,b=3;
b=a+b;
a=b-a;
b=b-a;
printf(" %d %d ",a,b);
}
| Is This Answer Correct ? | 44 Yes | 54 No |
Answer / saptarshi
void main()
{
char *p="string1";
char *q="string2";
p^=q^=p^=q;
printf("%s,%s",p,q);
}
swapping the base pointers of the two strings may work...
if they are declared as character arrays, then it is not
possible as we cannot modify the value of array base
pointers...
| Is This Answer Correct ? | 10 Yes | 26 No |
Answer / ramu pasupuleti
#include<stdio.h>
#include<conio.h>
{
printf("enter a,b values");
a=a+b;
a=a-b;
b=a-b;
printf("%d%d",a,b);
getch();
}
| Is This Answer Correct ? | 2 Yes | 18 No |
Answer / srinath, hyd
main()
{
int a=5,b=3;
a=a+b;
b=a-b;
a=a-b;
printf(" %d %d ",a,b);
getch();
}
| Is This Answer Correct ? | 7 Yes | 26 No |
How. To pass the entrance test
What are the 5 types of organizational structures?
how to find anagram without using string functions using only loops in c programming
Explain what is the best way to comment out a section of code that contains comments?
write a program to display numbers from 1 to 10 and 10 to 1?
how to reverse string "Hello World" by using pointers only. Without any temp var
What is a #include preprocessor?
Why dont c comments nest?
Why calloc is better than malloc?
I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.
Explain what are linked list?
Ow can I insert or delete a line (or record) in the middle of a file?