Logical Not ! operator in C with Examples
! is a type of Logical Operator and is read as “NOT” or “Logical NOT“. This operator is used to perform “logical NOT” operation, i.e. the function similar to Inverter gate in digital electronics.
Syntax:
!Condition // returns true if the conditions is false // else returns false
Below is an example to demonstrate ! operator:
Example:
// C program to demonstrate working // of logical NOT '!' operators #include <stdio.h> int main() { // Taking a variable a // and set it to 0 (false) int a = 0; // logical NOT example // Since 0 is considered to be false // !a will yield true if (!a) printf("Condition yielded True\n"); else printf("Condition yielded False\n"); // set a to non-zero value (true) a = 1; // Since a non-zero value is considered to be true // !a will yield false if (!a) printf("Condition yielded True\n"); else printf("Condition yielded False\n"); return 0; } |
chevron_right
filter_none
Output:
Condition yielded True Condition yielded False
Recommended Posts:
- Code Optimization Technique (logical AND and logical OR)
- Arrow operator -> in C/C++ with Examples
- What are the differences between bitwise and logical AND operators in C/C++?
- Order of operands for logical operators
- dot (.) operator in C/C++
- sizeof operator in C
- C++ | Nested Ternary Operator
- Operands for sizeof operator
- When should we write our own assignment operator in C++?
- To find sum of two numbers without using any operator
- Result of comma operator as l-value in C and C++
- A comma operator question
- Operator Precedence and Associativity in C
- Conditional or Ternary Operator (?:) in C/C++
- C++ | Operator Overloading | Question 9
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




