Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

swapping without third variable c++

//Author: Subodh
        //! Swap two number using XOR operation
        cout << "Before, n1 = " << num1 << ", n2 = " << num2 << endl;
        num1 = num1 ^ num2, num2 = num1 ^ num2, num1 = num1 ^ num2;
        cout << "After, n1 = " << num1 << ", n2 = " << num2 << endl;
 
PREVIOUS NEXT
Tagged: #swapping #variable
ADD COMMENT
Topic
Name
7+3 =