Abstract

The Boolean NOT operator, AKA logical NOT operator, is a unary prefix operator, which chages a Boolean true to false, and a Boolean false to true.

Form

boolean-not-operator
!

Domain

boolean-not-operator
!: int × int
!: long × long
!: unsigned int × unsigned int
!: unsigned long × unsigned long

Semantics

boolean-not-operator
  1. The operand is evaluated.
  2. if the operand value is integral, but smaller than an int, it is coerced (widened) to an int.
  3. A value of 0 is interpredted as false.
  4. Any value not 0 is interpredted as true.
  5. The result is the Boolean NOT of the interpreted value:
    Boolean NOT
    OperandResult
    01
    10
  6. I.E., the result is 1 if the operand is 0, and the result is 0 if the operand is not 0.

Precedence


Higher
Subscript [ ]
UnaryPostfix ++ --
Prefix ++ -- + - ! ~ ()
Arithmetic Multiplicative * / %
Additive + -
Shift >> <<
ComparisonRelational < <= > >=
Equality == !=
Bitwise Bitwise AND &
Bitwise XOR ^
Bitwise OR |
Boolean Boolean AND &&
Boolean OR ||
Conditional ? :
Assignment = += -= *= /= %= &= |= ^= <<= >>=
Sequence ,

Remarks

Example

#include <stdio.h>

void LogicalNot (int A);

int main () {
  LogicalNot (0);
  LogicalNot (1);
  LogicalNot (-1);
  LogicalNot (15);
  return 0;
}

void LogicalNot (int A) {
  printf ("! %i = %i\n", A, (! A));
}

Output


    

Reference Links

Boolean AND Operator boolean-and-operator &&
Boolean OR Operator boolean-or-operator ||

Other Languages

C Now
C Boolean NOT Operator !
C++ Now C++ Boolean NOT Operator !
Java Now Java Boolean NOT Operator !
Pascal Now Pascal Boolean NOT Operator !
PHP Now PHP Boolean NOT Operator !