What is !0 in C?

后端 未结 5 1794
傲寒
傲寒 2020-12-06 09:59

I know that in C, for if statements and comparisons FALSE = 0 and anything else equals true.

Hence,

int j = 40
int k = !j

k == 0 // this is true
         


        
5条回答
  •  独厮守ぢ
    2020-12-06 10:39

    The Bang operator (!) is the logical not operator found commonly in C, C++ and C#, so

    !0 == 1
    !1 == 0
    

    This is based on the language characteristic of what is interpreted to be either true or false... in more modern languages it would be like this

    !false == true
    !true == false
    

    See DeMorgan Law concerning truth tables...

提交回复
热议问题