Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The ! (logical NOT) operator is a unary operator that performs logical negation. It yields an int value of 1 if its operand compares equal to zero, and 0 if its operand compares unequal to zero. Syntax
!operand
Operand Constraints The operand must be of a scalar type. In C, scalar types include:
  • Arithmetic types (integer and floating-point types)
  • Pointer types
Evaluation and Type Semantics Regardless of the operand’s original data type, the result of the ! operator is strictly of type int. The evaluation follows these rules:
  • If operand == 0 (or NULL for pointers), !operand evaluates to 1.
  • If operand != 0 (or non-NULL for pointers), !operand evaluates to 0.
Semantically, the expression !E is exactly equivalent to (0 == E). Precedence and Associativity The ! operator belongs to the unary operators group (Precedence Level 2 in C).
  • Associativity: Right-to-left.
  • Precedence: It binds more tightly than binary arithmetic, relational, equality, and binary logical operators.
Because of its high precedence, an expression like !a == b is parsed as (!a) == b. To negate the result of an equality check, explicit grouping parentheses are required: !(a == b). Double Negation (!!) Because ! forces any non-zero value to 0 and any zero value to 1, applying the operator twice sequentially evaluates to a normalized integer boolean representation of the original scalar:
!!operand
  • If operand is 0, !!operand evaluates to 0.
  • If operand is any non-zero value (e.g., 42, -3.14, or a valid memory address), !!operand evaluates to 1.
Master C with Deep Grasping Methodology!Learn More