Logical Operators are used very frequently in programming. The logical operators symbols are almost the same in all the languages. logical operators in c, logical operators in java and in many more languages are the same. In the following paragraph we will try to elaborate these in an easy way.
There are many occasions when we face complex conditions to make a decision. This means that a decision depends upon more than one condition in different ways. Here we combine the conditions with AND or OR. For example, a boy can be selected in basket ball team only if he is more than 18 years old and has a height of 6 feet. In this statement a boy who wants to be selected in the basket ball team must have both the conditions fulfilled. This means that AND forces both the conditions to be true. Similarly we say that a person can be admitted to the university if he has a BCS degree OR BSC degree. In this statement, it is clear that a person will be admitted to the university if he has any one of the two degrees.
In programming we use logical operators ( && and  ) for AND and ORrespectively with relational operators. These are binary operators and take two operands. These logical operators use logical expressions as operands, which return TRUE or FALSE. The following table (called truth table) can be used to get the result of the && operator and  operator with possible values of their operands. It is used to explain the result obtained by the && and  operators.
Expression 1

Expression 2

Expression 1 && Expression 2

Expression 1  Expression 2

True

False

False

True

True

True

True

True

False

False

False

False

False

True

False

True

No comments:
Post a Comment