DEV Community

loading...

Discussion on: How to swap two variable value without using temporary variable

Collapse
bacloud14 profile image
bacloud14 • Edited

that's a language feature, what about a mental hack ? x) here it is:

a = 1
b = 2
a = a + b
b = a - b
a = a - b
Enter fullscreen mode Exit fullscreen mode

Care about overflows though :)

Collapse
zippytyro profile image
Shashwat Verma

haha interesting