0
What does the !(NOT) operator do in c
decimal 6=binary 110. So, !(6) =1. But when I run the following c program i get no output if(!(6)) printf("1"); What do ! operator do in c? Why is !(6) notEqualTo 1
3 Antworten
+ 5
You're talking about this I think https://www.sololearn.com/learn/4076/?ref=app
+ 2
Yes, I thought so.
For C++ using <bitset> helps in such a case.
https://code.sololearn.com/cAqz7pLLT8Nu/?ref=app
+ 1
As Mert Yazıcı already mentioned, you are confusing bitwise complement and not operator.
printf("%d\n",~6); \\ prints -7
printf("%d\n",!6); \\ prints 0
Why is that?
The decimal number is represented by more bits than only three bits. The minus comes to play because the first bit (for signed ints) represents the sign.
For any *logical* operation, it is either 1 or 0.
Any number different from 0 is considered as 1 (=true)
So if you say !6 it becomes 0.