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 can a program be made to print the line number where an error occurs?

0 Answers  


what is the output of the following program? #include<stdio.h> void main() { float x=1.1; while(x==1.1) { printf("\n%f",x); x=x-0.1; } }

6 Answers  


Can the sizeof operator be used to tell the size of an array passed to a function?

0 Answers  


Describe the modifier in c?

0 Answers  


What is this pointer in c plus plus?

0 Answers  


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

0 Answers  


Explain output of printf("Hello World"-'A'+'B'); ?

0 Answers  


illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question

0 Answers  


Can we use any name in place of argv and argc as command line arguments?

0 Answers  


study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above

15 Answers   Accenture, TCS,


What is the use of a static variable in c?

0 Answers  


What is extern keyword in c?

0 Answers  


Categories