What is !0 in C?

后端 未结 5 1793
傲寒
傲寒 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:22

    §6.5.3.3/5: "The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int."

    The other logical operators (e.g., &&, ||) always produce either 0 or 1 as well.

提交回复
热议问题