Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
 Do you have a collection of Interview Questions and interested to share with us!! Please send that collection to along with your userid / name. ThanQ

 Categories  >>  Software  >>  Testing  >>  Manual Testing

 Automation Testing Interview Questions Manual Testing Interview Questions QA Concepts Interview Questions Mobile Testing Interview Questions Test Cases Interview Questions Test Documents Reporting Interview Questions Testing AllOther Interview Questions
Question
`Swap 2 variables without using a temp variable`
Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By

Re: Swap 2 variables without using a temp variable
# 1
a,b
a=a+b
b=a-b
a=a-b

 Is This Answer Correct ? 20 Yes 0 No
Guest

Re: Swap 2 variables without using a temp variable
# 2
int x,y;
x=x+y;
y=x-y;
x=x-y;

 Is This Answer Correct ? 12 Yes 1 No
Mfsi_satyakamm

Re: Swap 2 variables without using a temp variable
# 3
if a=5 and b=3 are two variables, then add them i e
a=a+b; a=8
b=a-b; b=5
a=a-b; a=3

 Is This Answer Correct ? 11 Yes 0 No
Sheetal

Re: Swap 2 variables without using a temp variable
# 4
try this one line swaping of two variables

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

 Is This Answer Correct ? 3 Yes 5 No
S N