Is there a built in swap function in C?

user1149207 picture user1149207 · Jan 14, 2012 · Viewed 63k times · Source

Is there any built in swap function in C which works without using a third variable?

Answer

Saif picture Saif · Jan 14, 2012

No.
C++ builtin swap function: swap(first,second);
Check this: http://www.cplusplus.com/reference/algorithm/swap/

You can use this to swap two variable value without using third variable:

a=a^b;
b=a^b;
a=b^a;

You can also check this:

https://stackoverflow.com/questions/756750/swap-the-values-of-two-variables-without-using-third-variable

How to swap without a third variable?