Thursday, 17 October 2013

The Negation Operator in Programming Languages

The Negation Operator in Programming

There is another logical operator that is called logical negation. The sign ! is used for
this operator. This operand enables a programmer to ‘reverse’ the meaning of a
condition. This is a unary operator that has only a single condition as an operand. The
operator ! is placed before a condition. If the original condition (without the !
operator) is false then the ! operator before it converts it to true and the statements
attached to this are executed.
Look at the following expression
if ( ! (age > 18 ))
cout << “ The age is less than 18”;
Here the cout statement will be executed if the original condition (age > 18) is false
because the ! operator before it reverses this false to true.
The truth table for the logical negation operator ( ! ) is given below.


negation operator in perl, negation operator in vba, negation operator in php,  negation operator python, negation operator in javascript, negation operator java

No comments:

Post a Comment