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

Why should I use standard library functions instead of writing my own?

0 Answers  


Difference between exit() and _exit() function?

0 Answers  


What is Full Form of C and Why We use C

23 Answers  


What is scope of variable in c?

0 Answers  


wht is the difference between KPO and BPO ?

2 Answers   Accenture, BPO, HCK, HCL, Infosys,


hw can we delete an internal node of binary search tree the internal node has child node..plz write progarm

0 Answers   TCS,


A array contains dissimilar element how can we count, and A array contains dissimilar element how can we store in another array with out repetition.

4 Answers  


Explain how can a program be made to print the line number where an error occurs?

0 Answers  


Q.11 Generate the following pattern using code in any language(c/c++/java) for n no. of rows 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

2 Answers  


Why n++ execute faster than n+1 ?

2 Answers  


What is the value of uninitialized variable in c?

0 Answers  


4.A function 'q' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as: A)int (*q(char*)) [] B)int *q(char*) [] C)int(*q)(char*) [] D)None of the Above

6 Answers   Accenture,


Categories