Relational Operators
Relational Operators
- Relational operators are used to compare two values (the left side and the
right side). Since the operator needs a left side and a right side, it is a
binary operator.
- An expression involving relational operator/s can be called as a relational
expression.
- The result of the relational expression can be either 0 or 1 (integer data
type). 0 stands for false and 1 stands for true. (Back then, the result of the
relational expression was said to be 0 (false) or non-zero (true). 0 or 1 is
less confusing and easier to recall.)
- Even if the comparison involves comparing two floats, the result of the
relational expression is still 0 or 1 (still integer data type as result).
Parentheses ()
Multiplication and Division */%
Addition and Subtraction +-
Relational operators < > <= >= == !=
- Logical operators (logical and, logical or) can be used to evaluate two
values (the left side and the right side). Since the operator needs a left
side and a right side, it is a binary operator.
- It is more common to use logical operators with relational expressions.
Relational expressions would be on the left side and the right side of the
logical operator.
- The logical not (!) is not a binary operator since it only requires a right
side. The logical not is also called as negation.
- An expression involving logical operator/s can be called as a logical
expression.
- The result of the logical expression can be either 0 or 1 (integer data
type). 0 stands for false and 1 stands for true.
- This symbol (|) is called the bar and is commonly located above \ on the
keyboard.
|| (logical or)
Left Right Result
1 1 1
1 0 1
0 1 1
0 0 0
Parentheses ()
Multiplication and Division */%
Addition and Subtraction +-
Relational operators < > <= >= == !=
Logical operators && ||
printf(“\n%d”,!(x == y) );
//12 == 6 is 0. Negating 0 is 1.