+ 7
Can anyone explain the below code
int main() { bool x=1,y=0; cout << ++x << ~~y; } output -- 10 what is the ~~ operator??
13 odpowiedzi
+ 7
~~ is not an operator
~ (tilde) is a unary operator. It is the bitwise not.
What does it do?
It turns all the binary 1s to 0s and binary 0s to 1s.
So, by using it twice, you are cancelling out the effect of both. So, 0 remains 0.
+ 9
Hey!
That's one of my quiz factory questions (Not yet approved)Where did you find that?😮
+ 7
@Pixie same place...when I rate the quiz submissions I saw this one...and I stuck there..
So u can tell me better than anyone...how did u get the output 10??
+ 6
but when x=0,it will increment and give the output 10 again..
+ 6
@Chintu Verma
why??
+ 4
PS: Good on you for rating submissions. Not many people do it here. But those who do are the heroes this community deserves 😃
+ 4
thnxx...🤗🤗🤗
+ 2
As Venkatesh said, it is the "bitwise not" operator, meaning it reverses 0s and 1s. Assume byte y = 0x00100100; therefore ~y == 0x11011011; reversing it again gets you back to the original value.
+ 1
it is the bitwise not two times. try with a type other than book, say int and you may get different result.
+ 1
The bool values only output 0 or 1 when using cout. There are no spaces output when using cout in this example.
+ 1
looks like the ++ operator did not increment the bool x, and the double ~ either returned the bool y to 0 (false) or did not change it. the output is a concatenation of values xy, or 10
+ 1
this code is wrong
+ 1
!!