BM Balmiki Mandal 30 Jun 2023 3 views 0 comments C Programming

Logical NOT operator- programming tutorial

The Logical NOT (!) Operator in C

The logical NOT (!) operator in C is used to reverse the logical state of its operand. If a condition is true, then the logical NOT operator will make it false. And if it is false, it will return true.

syntax for the logical NOT operator is:

!operand

where operand is an expression that evaluates to a Boolean value.

For example, the following code:

int a = 10;
int b = 20;

int result1 = !(a == 10);
int result2 = !(b == 20);

will return 0 and 1, respectively. This is because the first condition, a == 10, is true, so the logical NOT operator reverses it to false. The second condition, b == 20, is false, so the logical NOT operator reverses it to true.

The logical NOT operator is often used in decision-making statements, such as if statements and while loops. For example, the following code:

if (!(a == 10)) {
  printf("The value of a is not equal to 10.\n");
}

will print the message "The value of a is not equal to 10" if the value of a is not equal to 10.

Here is a table of the truth values for the logical NOT operator:

operand | result
------- | --------
0       | 1
1       | 0

As you can see, the logical NOT operator returns 1 if the operand is false, and 0 if the operand is true.

 

Share:

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Bit wise operators Assignment

Bitwise Operators practical assignment: Take runtime input, bit-level manipulation, and different data units r...

AG Anvesh G 27 Sep 2026
Understanding Float and Double Binary Representation in C

Understanding Float and Double Binary Representation in CIntroduction:When we store decimal numbers such as 10...

AG Anvesh G 31 May 2026
Topic-wise C Programming Interview Questions

C Programming Interview Questions – Topic Wise1. IntroductionC programming is one of the most important langu...

AG Anvesh G 30 May 2026