Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Logical Negation Operator: !

 

The latest version of this topic can be found at Logical Negation Operator: !.

Syntax

  
! cast-expression  

The logical negation operator (!) reverses the meaning of its operand. The operand must be of arithmetic or pointer type (or an expression that evaluates to arithmetic or pointer type). The operand is implicitly converted to type bool. The result is true if the converted operand is false; the result is false if the converted operand is true. The result is of type bool.

For an expression e, the unary expression !e is equivalent to the expression (e == 0), except where overloaded operators are involved.

The not operator is the text equivalent of !. There are two ways to access the not operator in your programs: include the header file iso646.h, or compile with the /Za (Disable language extensions) compiler option.

// expre_Logical_NOT_Operator.cpp  
// compile with: /EHsc  
#include <iostream>  
using namespace std;  
  
int main() {  
   int i = 0;  
   if (!i)  
      cout << "i is zero" << endl;  
}  

Expressions with Unary Operators
C++ Operators
C++ Built-in Operators, Precedence and Associativity
Unary Arithmetic Operators

Show: