Search code examples
clanguage-lawyerc89

!0 guaranteed to be 1 in C89?


I've searched the standard but didn't notice the mentioned part.

Is it just "anything but 0" and 1 or it is compiler-dependent?


Solution

  • 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.

    Appears in C89/C90, C99, and C11.