0

bitwise xor and not operator

https://code.sololearn.com/cgYFcQ92dxUs/#c https://code.sololearn.com/cCRwH0pbo0wj/#c Can anyone explain me the above code.. How the output comes as 10 1 and 1

12th Oct 2018, 11:40 AM
Dhiviya Thirumavalavan
Dhiviya Thirumavalavan - avatar
2 Answers
+ 2
In first code, xor makes bits the same 0 and bits different 1 so: x=0b0001 y=0b1010 x^=y makes x 0b1011 y^=x makes y 0b0001 x^=y makes x 0b1010 In the second code: !a?b?!c:!d:a is the same as: if (!a) if (b) !c else !d else a Since a is non-zero, it is true so not a is false so the value of a is printed.
12th Oct 2018, 1:46 PM
John Wells
John Wells - avatar
+ 1
John Wells Thank u so much
15th Oct 2018, 7:19 AM
Dhiviya Thirumavalavan
Dhiviya Thirumavalavan - avatar