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

Describe the order of precedence with regards to operators in C.

0 Answers  


Which of the following about automatic variables within a function is correct ? a.its type must be declared before using the variable b.they are local c.they are not initialised to zero d.they are global.

6 Answers   FCI, TCS,


Tell me when would you use a pointer to a function?

0 Answers  


main() { int i=0; while(+(+i--)!=0) i-=i++; printf(i); }

3 Answers  


how to find the binary of a number?

10 Answers   Infosys,






What does static variable mean in c?

0 Answers  


How do you generate random numbers in C?

0 Answers  


List some applications of c programming language?

0 Answers  


Who invented bcpl language?

0 Answers  


#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }

0 Answers   Wilco,


Describe static function with its usage?

0 Answers  


Please write the area of a RIGHT ANGLED TRIANGLE.

1 Answers  


Categories