What is the output of the below code and why?
------------------------The above code performs swap operation between variables var_1 and var_2.Let us look at the explanation below.
var_1 ^ = var_2 is expanded as var_1 = var_1^var_2
This represents XOR operation between var_1 and var_2.
For the first statement, var_1 ^ = var_2
=> var_1 = (100)^(200) = (000100000000)^(001000000000) = 001100000000 = 300
For the second statement, var_2 ^ = var_1
=> var_2 = (200)^(300) = (001000000000)^(001100000000) = 000100000000 = 100
For the third statement, var_1 ^ = var_2
=> var_1 = (300)^(100) = (001100000000)^(000100000000) = 001000000000 = 200
The final output is 200,100.
----------------------------------------
The above code snippet involved below learning:
0 Comments