Illustrate with an example that the unary negation operator ! is useful as a test for zero.

Q7. Illustrate with an example that the unary negation operator ! is useful as a test for zero.

Ans. The logical NOT operator (!) negates or reverse is false, and vice versa. Or we can say, if the expression is non-zero then !expression is zero (0) and if the expression is zero (0), then ! expression is 1.

For example:

!(5)  results into 0 (false) because 5 is non zero (that is, true).

!(0) results into 1 (true) because 0 is zero (that is, false).

Leave a Reply

Your email address will not be published. Required fields are marked *

109 Views
%d bloggers like this: