DEV Community

Discussion on: Swapping two numbers, w/o a temp variable

Collapse
 
philnash profile image
Phil Nash

Yeah, but not in real code! I'd prefer it were readable over assigning one extra variable. You've got to find some specific conditions to make this the better code to use!

Thread Thread
 
kebby profile image
Tammo 'kb' Hinrichs

I actually used this in real code once, in an assembly inner loop where I was really running out of registers :), but you're right of course.

Related question: Did anyone here ever have to reverse a string? :D

Thread Thread
 
hakash profile image
Morten Olsrud

Not in an interview, but in a quiz somewhere. It was an entry level one so only restriction was to not use the built in functions.