+ 2

what is the Output and explain it.. (need good explanation...)

https://code.sololearn.com/ctNQAMuikpik/?ref=app

21st Jul 2020, 10:04 AM
Dinesh S
Dinesh S - avatar
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 🙂
21st Jul 2020, 10:14 AM
v@msi😉
v@msi😉 - avatar
+ 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.🙂
21st Jul 2020, 10:32 AM
Arsenic
Arsenic - avatar
+ 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
21st Jul 2020, 10:20 AM
Sanjyot21
Sanjyot21 - avatar