How to swap two variables, without using third variable ?

Answers were Sorted based on User's Feedback



How to swap two variables, without using third variable ?..

Answer / priyam

b=a*b/(a=b);

Is This Answer Correct ?    1 Yes 8 No

How to swap two variables, without using third variable ?..

Answer / vinay kumar shukla

i am not giving answer
all above answer for swaping integer type variables without
third
i want answer in string type

Is This Answer Correct ?    6 Yes 15 No

How to swap two variables, without using third variable ?..

Answer / saumya

Thanks a lot guys. It is giving very good analysis.

Is This Answer Correct ?    7 Yes 19 No

How to swap two variables, without using third variable ?..

Answer / koneru gowtham

plz check 3 aswer is perfect, 2 one mat be wrong in some cases

Is This Answer Correct ?    47 Yes 63 No

How to swap two variables, without using third variable ?..

Answer / kumar

Using Assembly language( Using Accumulator)...Without using
any arithmatic...without using any Pointer...without
declaring third varible

int a = 20;
int b = 10;
__asm
{
mov EAX,b
push EAX
mov EAX,a
mov b,EAX
pop EAX
mov a,EAX
}

Is This Answer Correct ?    17 Yes 33 No

How to swap two variables, without using third variable ?..

Answer / meenama

The first two answers are correct. Third will FAIL in the
case the second num is 0. The #19 one still uses a third
variable.

Is This Answer Correct ?    5 Yes 21 No

How to swap two variables, without using third variable ?..

Answer / mangesh

#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
clrscr();
printf("\nEnter two numbers:");
scanf("%d%d",&a,&b);
printf("\nThe numbers after swapping are %d %d",b,a);
getch();
return 0;
}

Is This Answer Correct ?    0 Yes 18 No

How to swap two variables, without using third variable ?..

Answer / rehan

#include<stdio.h>
main()
{
int a,b;
printf("Enter any two numbers\n");
scanf("%d%d",&a,&b);
printf("The values before swapping are\n%d %d\n",a,b);
swap(&a,&b);
printf("The values after swapping are\n%d %d\n",a,b);
getch();
}

swap(*x,*y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

Is This Answer Correct ?    5 Yes 24 No

How to swap two variables, without using third variable ?..

Answer / divakar

a=a*b/(b=a);

Is This Answer Correct ?    25 Yes 57 No

How to swap two variables, without using third variable ?..

Answer / javaskills

x = y | (y=x);

Is This Answer Correct ?    11 Yes 54 No

Post New Answer

More C Code Interview Questions

main() { char p[ ]="%d\n"; p[1] = 'c'; printf(p,65); }

2 Answers  


Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

1 Answers  


Write a program that find and print how many odd numbers in a binary tree

1 Answers  


main(){ char a[100]; a[0]='a';a[1]]='b';a[2]='c';a[4]='d'; abc(a); } abc(char a[]){ a++; printf("%c",*a); a++; printf("%c",*a); }

2 Answers  


#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }

1 Answers  


write a c-program to display the time using FOR loop

3 Answers   HCL,


void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

2 Answers  


Cau u say the output....?

1 Answers  


how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.

0 Answers   Mbarara University of Science and Technology,


#define clrscr() 100 main() { clrscr(); printf("%d\n",clrscr()); }

2 Answers  


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


4. Main() { Int i=3,j=2,c=0,m; m=i&&j||c&I; printf(“%d%d%d%d”,I,j,c,m); }

2 Answers   Broadridge,


Categories