How to swap two numbers without using a temporary variable ? | C ++ program to swap two numbers . Including header file . ; Function to swap the numbers . ; same as a = a + b ; same as b = a - b ; same as a = a - b ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void swap ( int & a , int & b ) { a = ( a & b ) + ( a b ) ; b = a + ( ~ b ) + 1 ; a = a + ( ~ b ) + 1 ; cout << " After ▁ swapping : ▁ a ▁ = ▁ " << a << " , ▁ b ▁ = ▁ " << b ; } int main ( ) { int a = 5 , b = 10 ; swap ( a , b ) ; return 0 ; }