The complementation operation being used here is like NOT gate in digital logic . So the functionality is same as that of NOT gate.
Hence when we do the complementation of a number , the bits of the original number are toggled .
Hence binary representation of 10 in 32 bits : 28 0's followed by "1010"..
So by doing complementation we get 28 1's followed by "0101"..
Now we know :
Numbers are stored in 2's complement representation in computer for sake of simplicity of its usage in arithmetic circuits and unique representation of '0' as well..So
a) If MSB is 0 , the number itself gives true magnitude.
b) If MSB is 1 , we need to take 2's complement of that number to get true magnitude and then add '-' sign to it.
So in this case after complementation we have 28 1's followed by "0101" . So we need to take 2's complement to get true magnitude of the number..
Taking 2's complement we have : 28 0's followed by "1011" ==> -11
Hence we obtain -11 as the output of the program..
P.S. : There is difference between '!' and '∼' operator . The first one is "logical not operator also known as negation" whereas second one is bitwise NOT known as complementation operator.