Answer Posted / rajeshwar raja
Swap(int* a, int* b)
{
(*a) ^= (*b) ^= (*a) ^= (*b);
}
Explanation:
Expressions are evaluated from right to left.
Take the right most operation (*a) ^= (*b), its is short
hand XOR operation between 'a' and 'b'.
Assume a = 2 and b = 3.
a = 2 ^ 3 = 1
Next operation (*b) ^= (*a),
b = 3 ^ 1 = 2 (Note a is 1 now) ***(b is 2)***
Next operation (*a) ^= (*b)
a = 1 ^ 2 = 3 (Note b is 2 now) ***(a is 3)***
SWAPPED!!!
It can swap complex data structures also.
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What is stream in oop?
What is difference between abstraction and encapsulation?
What are the components of marker interface?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
What is the types of inheritance?
Why is object oriented programming so hard?
What is ambiguity in inheritance?
Why is encapsulation used?
What is encapsulation in oop?
What is oops concept with example?
What is static modifier?
What is polymorphism what is it for and how is it used?
What is byval and byref? What are differences between them?
What are main features of oop?
What is encapsulation with real life example?