a=5,b=2 a!=!!b What does the operation do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

a=5,b=2 a!=!!b What does the operation do?

16th Jul 2021, 4:09 AM
Durga M
Durga M - avatar
3 Answers
+ 5
In "C", a non zero integer is "true"(so a is true and b is also true) and the "!" operator is the NOT operator. Your second line reads as; a is NOT equal to (NOT NOT b) which is equivalent to; a is NOT equal to b (5 is not equal to 1) and the result is "true" (i.e one(1)). In case you are confused, let me explain further: b was originally 2 (which is true) !b becomes false (i.e 0) !!b becomes true (i.e 1) a != !!b means 5 is not equal to 1.... and that statement is true (1)
16th Jul 2021, 4:58 AM
David Akhihiero
David Akhihiero - avatar
+ 3
Yes Calvin Thomas, that is a concise way of explaining it
16th Jul 2021, 10:43 AM
David Akhihiero
David Akhihiero - avatar
+ 2
Durga M I use '!!' to extract the boolean value from an int. It's like the bool() function in Python, except that the result is in the integer form.
16th Jul 2021, 7:20 AM
Calvin Thomas
Calvin Thomas - avatar