can u write a program in C, which does not use = (eqaul)or
any arithmatic assignment(like -=,+=,*= etc) operator to
swap to number?
Answer Posted / anish
Simple... use XOR (^) operator...
example suppose,
x=101 (binary)
y=010 (binary)
now,
Execute : x=x^y; -->> from LSB 1^0=1 0^1=1 1^0=1
now x=111
Execute : y=x^y; -->> from LSB 1^0=1 1^1=0 1^0=1
now y=101 (101 used to be the value of x)
Execute : x=x^y; -->> from LSB 1^1=0 1^0=1 1^1=0
now x=010 (010 used to be the values of y)
code snippet
{
x=10;
y=30;
//swap x and y
x=x^y;
y=x^y;
x=x^y;
}
now x=30 and y=10
any doubts please ask me....
| Is This Answer Correct ? | 3 Yes | 8 No |
Post New Answer View All Answers
what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?
Explain heap and queue.
Which header file is essential for using strcmp function?
How do you determine a file’s attributes?
using for loop sum 2 number of any 4 digit number in c language
What does %c do in c?
Is there any demerits of using pointer?
Simplify the program segment if X = B then C ← true else C ← false
What does p mean in physics?
What happens if header file is included twice?
What's a good way to check for "close enough" floating-point equality?
What is the scope of local variable in c?
What is the basic structure of c?
Can we assign string to char pointer?
Explain main function in c?