You are watching: Which of the following is a relational operator?
Relational operators room binary meaning they require two operands.
Relational operators have actually left to ideal associativity. Left to right associativity method that as soon as two operators of same precedence space adjacent, the left most operator is evaluated first.
|=||Greater than or equal to|
Relational Expression Examples
x > y
x == y
Note: It have the right to be straightforward to forget that equal to is “==” and not “=” i beg your pardon is assignment. In numerous cases, the compiler won’t note this as an error since x==y and also x=y room both valid expressions.
What is the result of a relational expression?
Relational expressions space Boolean expressions and thus space equal to one of two people true or false.
5 > 4
5 == 5
5 != 5
1 > 3
1 >= 1
How a regimen treats true and false
C++ programs keep true and also false in memory as numbers.
false is stored together 0
true is stored together 1
Relational operator precedence and also relationship to the various other operators
Note just how the relational operator rank in precedence to the mathematical and assignment operators. Also, keep in mind that the much less than/greater 보다 operators have greater precedence 보다 the equal/not same relational operators.
|*, /, %|
|>, >=, bool data form variable. As detailed in the example, programmers regularly enclose relational expression in parentheses to enhance readability. |
int x = 5;int y = 10;bool result;// Assign an outcome of relational expression to bool form variableresult = x > y; // result is falsecout y: " y / 5; // result is true// equivalent, parentheses are not needed yet adds readability hereresult = (x + 10) > (y / 5); // bool change is output as 0 or 1 rather of true or falsecout (y / 5): "
Comparing characters with relational operators
As questioned earlier, characters are save on computer in memory as integers. Thus, you have the right to compare personalities using relational expressions just like they were numbers.
char testCharacter = "c";if (testCharacter == "c") cout The > and ‘a’ is false.
Comparing strings v relational operators
You can likewise compare strings using relational operators. As soon as a relational operator is offered with strings, the integer worth of each character the the left operand is compared to the integer value of each character of the best operand working from left come right.
“tim” == “tom” // false because the second characters i and also o perform not match
“Tim” == “tim” // false due to the fact that T and also t do not match
Character trial and error functions
All the these attributes have a solitary character parameter so you have the right to use them favor this