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
which feature are not hold visual basic of oop?
Why it is called runtime polymorphism?
What are properties in oop?
what is the sylabus for priliminaries?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
What is a class oop?
Why do we use class in oops?
What is abstraction in oops?
Why do we use oops?
What is encapsulation selenium?
What is pure oop?
What is inheritance in oop?
Is oop better than procedural?
Can abstract class have normal methods?
What is destructor give example?