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.



// returns true if the conditions is false
// else returns false

Below is an example to demonstrate ! operator:






// 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");
        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");
        printf("Condition yielded False\n");
    return 0;



Condition yielded True
Condition yielded False

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.