Swap Two Variables Without a Temporary Variable
Given two integers a and b, swap their values without using a third variable.
Input
One line containing a b.
Output
Print the swapped values: b a.
Explain the applicability and potential risks of different approaches.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Standard Input
Execution Result:
