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



How to write a program for swapping two strings without using 3rd variable and without using strin..

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

How to write a program for swapping two strings without using 3rd variable and without using strin..

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

How to write a program for swapping two strings without using 3rd variable and without using strin..

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

How to write a program for swapping two strings without using 3rd variable and without using strin..

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

How to write a program for swapping two strings without using 3rd variable and without using strin..

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

How to write a program for swapping two strings without using 3rd variable and without using strin..

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

How to write a program for swapping two strings without using 3rd variable and without using strin..

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

Post New Answer

More C Interview Questions

What is the size of a union variable?

0 Answers  


What is the proper way of these job Tell me about there full work

0 Answers   EDS,


Where are some collections of useful code fragments and examples?

0 Answers   Celstream,


what about "char *(*(*a[])())();"

3 Answers   Oracle,


the format specified for hexa decimal is a.%d b.%o c.%x d.%u

7 Answers   TCS,






what is the output for the code : main() { int i,j; printf("%d %d ",scanf("%d%d",&i,&j)); }

20 Answers   Infosys,


what is the differnce between AF_INET and PF_INET?

5 Answers   Systems Plus, Wipro,


What is the purpose of scanf() and printf() functions?

0 Answers  


how to set Nth bit of a variable?

1 Answers  


WRITE A PROGRAM TO PRINT THE FOLLOWING OUTPUTS USING FOR LOOPS. A) * B) ***** *** * * ***** * * *****

2 Answers  


We can draw a box in cprogram by using only one printf();& without using graphic.h header file?

4 Answers   NIIT,


how to execute with out main in cprogram

15 Answers   Infosys,


Categories