How can you swap two variables without using a third?

Nick Karnik - Sep 24 '18 - - Dev Community

Moore's law is just an observation and not a real law like the Law of Gravity.

Over the years, developers have taken the increasing CPU speeds and Memory sizes for granted. Here's a warm-up interview question that I ask every candidate.

Let's assume the working memory for your function is 8-Bytes. You are given two 32-Bit Integers and you need to swap them. In other words, how can you swap two variables without using a third?

Please take your time to solve this and refrain from looking up solutions online or for answers below. This is your first step in becoming a Computer Scientist!


If you accepted this challenge, ❤️ it and follow me on Twitter.
. . . . . . . . . . . . . . . . . . . . .
Terabox Video Player