Write a program to exchange two variaables without temp

Answers were Sorted based on User's Feedback



Write a program to exchange two variaables without temp..

Answer / vijay

main()
{
int a, b;
a=a+b;
b=a-b;
a=a-b;
}

Is This Answer Correct ?    24 Yes 5 No

Write a program to exchange two variaables without temp..

Answer / sujith

another quick way is,

void main()
{
int a = 10, b = 5;
a ^= b ^= a ^= b;
}

Is This Answer Correct ?    7 Yes 0 No

Write a program to exchange two variaables without temp..

Answer / kadher

void main()
{
int a=10,b=5;
a=a^b;
b=a^b;
a=a^b;

}

Is This Answer Correct ?    6 Yes 0 No

Write a program to exchange two variaables without temp..

Answer / srinivas

main()
{
int a=3,b=2;

a = (a+b)-(b=a);

printf("a=%d,b=%d",a,b);
}
o/p:- a=2,b=3

Is This Answer Correct ?    2 Yes 0 No

Write a program to exchange two variaables without temp..

Answer / vijay

Sir,... im not comfortable with the 2nd ans cud pls explain
me .?????/

Is This Answer Correct ?    2 Yes 1 No

Write a program to exchange two variaables without temp..

Answer / haihere

Ans 3 is proper answer,coz in 1 it wont check for
range,,ans 3 is the rigt..

Is This Answer Correct ?    1 Yes 1 No

Write a program to exchange two variaables without temp..

Answer / sandeep rehlan

Sir, please explain me the 3rd and 6th answer because both
are the orrect way of swapping of two variables.

Is This Answer Correct ?    0 Yes 0 No

Write a program to exchange two variaables without temp..

Answer / suman ambardar

x=x+y
y=x-y
x=x-y

Is This Answer Correct ?    0 Yes 0 No

Write a program to exchange two variaables without temp..

Answer / {

void main()

Is This Answer Correct ?    0 Yes 11 No

Post New Answer

More C Interview Questions

What is the purpose of 'register' keyword in c language?

0 Answers  


What is a ternary operator in c?

0 Answers  


write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3

0 Answers   ADP,


explain how do you use macro?

0 Answers  


implement NAND gate logic in C code without using any bitwise operatior.

4 Answers   Alcatel,






Can we access array using pointer in c language?

0 Answers  


How will you allocate memory to double a pointer?

1 Answers  


Tell us the difference between these two : #include"stdio.h" #include<stdio.h> define in detial.

5 Answers  


What is the difference between c &c++?

0 Answers  


What is a stream in c programming?

0 Answers  


Why array starts with index 0

2 Answers  


If an old women's age is the same as her three grand daughters i,mean the number of days old child=the no of weeks old child=no of months old child .The total yrs of all these ppl is 114 yrs...then how old is the old woman? the yr has 365 days..and 30 days each month.

1 Answers   TCS,


Categories