In this post, we will see Relational and Boolean Expressions | PPL | Sebesta | Expressions and Assignment Statements | relational and boolean expressions, ppl, sebesta, expressions and assignment statements
4. Relational and Boolean Expressions
A relational operator is an operator that compares the values of its two operands. A relational expression has two operands and one relational operator.
The value of a relational expression is Boolean.
The syntax of the relational operators for equality and inequality differs among some programming languages. For example, for inequality, the C-based languages use != , Ada uses /= , Lua uses ~= , Fortran 95+ uses .NE. or <> , and ML and F# use <> .
"7" == 7
"7" === 7
is false, because no coercion is done on the operands of this operator.
The relational operators always have lower precedence than the arithmetic operators, so that in expressions such as
a + 1 > 2 * b
the arithmetic expressions are evaluated first.
Boolean expressions consist of Boolean variables, Boolean constants, relational expressions, and Boolean operators. The operators usually include those for the AND, OR, and NOT operations, and sometimes for exclusive OR and equivalence. Boolean operators usually take only Boolean operands (Boolean variables, Boolean literals, or relational expressions) and produce Boolean values.
The precedence of the arithmetic, relational, and Boolean operators in the C-based languages is as follows:
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=0eCfY9JgX1I