DEV Community

Discussion on: How can you swap two variables without using a third?

 
theodesp profile image
Theofanis Despoudis • Edited

That defeats the purpose of doing that plus you are making a difficult work of complicating things. I suspect is better if you use a temp variable after all!

Thread Thread
 
lewiscowles1986 profile image
Lewis Cowles

I suspect it's better if you don't try to copy with only two memory areas, but if you're going to worry about overflowing, then doubling storage size is the least complex thing you could do, and compatible with various CPU operating modes.