There are only three logical operators which are related with the logical decision.These are listed in the following table-

First two operators are used to combine the conditions i.e. to form a compound conditional expression.Third operator is used to inverse the condition.

For example,

x > y && k !=b12

This is termed as the logical expression.Whole expression also returns the Boolean value.That is, the above expression will return true when the both the conditions (x > y) and (k!=12) are true.If any one of these condition is false the expression will return false.

Consider another example,

m==99 || j <=10

This logical expression involves the logical OR operator.The expression will return true only when any one of the conditions (m==99 and j<=10) is true.If both condition are false, the whole expression will also expression will return false.

The third operator is know as logical NOT operator.This is the only unary logical operator and generally used to negate the condition.If we write this operator in front of any other relational or logical expression, the result of the expression will be inverted.That is, true will become false and false will become true.

For example,

x = 36 then

! (x > 40) will return true

! (x == 36) will return false

The following program will clear the idea of logical operators and expression.

First two operators are used to combine the conditions i.e. to form a compound conditional expression.Third operator is used to inverse the condition.

For example,

x > y && k !=b12

This is termed as the logical expression.Whole expression also returns the Boolean value.That is, the above expression will return true when the both the conditions (x > y) and (k!=12) are true.If any one of these condition is false the expression will return false.

Consider another example,

m==99 || j <=10

This logical expression involves the logical OR operator.The expression will return true only when any one of the conditions (m==99 and j<=10) is true.If both condition are false, the whole expression will also expression will return false.

The third operator is know as logical NOT operator.This is the only unary logical operator and generally used to negate the condition.If we write this operator in front of any other relational or logical expression, the result of the expression will be inverted.That is, true will become false and false will become true.

For example,

x = 36 then

! (x > 40) will return true

! (x == 36) will return false

The following program will clear the idea of logical operators and expression.

ReplyDeletenice article for beginners.thank you.

welookups C++

javacodegeeks