Boolean Expression
Boolean Expression
It is using the relational operators to represented less than or greater than to identified the expression is TRUE or FALSE. Below is the table that shows the sign of relational operator. Relational operator < <= > >= == != For example, Given 4 < 10, This is a Boolean Expression because the result for the expression is TRUE where 4 is less than 10. In the program also can write: If (I < 10) { printf (The value is under limit); } Function Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to
For more complex Boolean expressions can be built out of simpler expressions, below is show the Logical Boolean operators: Logical Boolean operators && || Function AND OR Example Tall && Fat (The man is tall and fat) Hot || cold (Would you like hot or cold for a cup of coffee?) ! NOT ! danger ( Not danger)
Boolean operator truth table: 1 = T (TRUE), 0 = F (FALSE) The && (AND) is an operator that produce a true result if both operand are true where the left-hand side is true and the right-hand side is true. This operation is same like multiply (*) function. Example in program: if (a==1 && b==1) { Printf (The system run); } Above program is show that the i value is between 2 until 19.
The || (OR) is an operator that produce a true result if either operand is true. This operation is same like add (+) function. Example in program:
if (a==0 || b==1) { Printf (The expression is TRUE); } Above program is show that the weight is less than 50 or weight more than 70 is fail on the weight test.
The ! (NOT) is an operator that takes a single true/false value and negates it where change false to true and true to false. Example in program: if (danger) { printf (Run faster); } else if (!danger) { printf (Cool down); }
Boolean expressions are also called as comparison expressions, conditional expressions, and relational expressions.