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

How does sizeof know array size?

0 Answers  


how do we remove the printed character in printf statement and write next it it

1 Answers  


What are the different types of control structures?

0 Answers  


Find the middle node in the linked list?? (Note:Do not use for loop, count and count/2)

6 Answers   Subex,


how many keywords are available in 'c' language a) 32 b) 34 c) 45 d) 48

1 Answers  






What are the advantages of Macro over function?

1 Answers  


what is the difference between embedded c and turbo c ?

1 Answers  


How can I write data files which can be read on other machines with different word size, byte order, or floating point formats?

0 Answers  


WAP that prints the number from 1 to 100. but for multiplies of three print "XXX" instead of the number and for the multiplies of five print "YYY" . for number which are multiplies of both three and five print "ZZZ"

3 Answers  


void main() {int i=2; printf("%d%d%d",i,++i,i++); getch(); }

9 Answers  


hi, which software companys will take,if d candidate's % is jst 55%?

0 Answers  


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

0 Answers  


Categories