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 ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }

1 Answers  


main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }

1 Answers  


Print an integer using only putchar. Try doing it without using extra storage.

2 Answers  


void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }

2 Answers  


void main() { int const * p=5; printf("%d",++(*p)); }

3 Answers   Infosys, Made Easy, State Bank Of India SBI,






source code for delete data in array for c

1 Answers   TCS,


What is data _null_? ,Explain with code when u need to use it in data step programming ?

0 Answers   Abbott,


#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

1 Answers  


write a program to Insert in a sorted list

4 Answers   Microsoft,


what is the code of the output of print the 10 fibonacci number series

2 Answers  


Finding a number which was log of base 2

1 Answers   NetApp,


What are the following notations of defining functions known as? i. int abc(int a,float b) { /* some code */ } ii. int abc(a,b) int a; float b; { /* some code*/ }

1 Answers  


Categories