Question:
How to swap the content of two variables without a temporary variable
Answer:
void swap(int a,int b)
{
a =a+b;
b=a-b;
a=a-b;
} Source: CoolInterview.com
void swap(int a,int b)
{
a =a*b;
b=a/b;
a=a/b;
} Source: CoolInterview.com
Answered by: raghu | Date:
| Contact raghu
void swap { t=a; a=b b=t; } Source: CoolInterview.com
Answered by: annam | Date:
| Contact annam
void swap(int a int b) { a=(a*b)/(b=a); } Source: CoolInterview.com
Answered by: nagini | Date:
| Contact nagini
void swap(int *a,int *b) { *a^=*b^=*a^=*b; } Source: CoolInterview.com
Answered by: jai | Date: 12/4/2007
| Contact jai
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|