+ 2
what is the Output and explain it.. (need good explanation...)
3 Answers
+ 3
The output is 0 bcz
1-(-1==~0);
~0 value is - 1
(-1==-1)is true so returns 1
1-1=0
đ
+ 2
Dinesh S "~" is bitwise NOT operator. It will convert all the zeros to one's and ones to zeros.
But you should know that the highest bit in an int variable is the so-called sign bit. If the highest bit is 1, the number is interpreted as negative. This encoding of positive and negative numbers is referred to as twoâs complement.
So when you switch the bits using NOT operator. This bit also get switched resulting in negative value.
Hope it's clear now.đ
+ 1
Dinesh S in this code you are declaring an integer variable x which is equal to x=1-(-1==~0) this expression.
~0 is equal to -1, so (-1==-1) is equal to 1. And 1-1 = 0. So the output of this code is 0