## Relational Operators

Relational operator are vital for do decisions. They permit us to compare numeric and also char (chars are treated choose numbers in C++) values to recognize if one is greater than, less than, same to, or no equal come another.

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.

Relational Operators definition
> Greater than
= 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
true
5 == 5
true
1
true
5 != 5
false
1 > 3
false
1 >= 1
true

### 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.

Precedence greatest to shortest
( )
*, /, %
+, -
>, >=, 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.

See more: Phone Case For Samsung Galaxy J7 Crown (S767Vl) Case, Samsung Galaxy J7 Crown Accessories

## 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

“abc”

## Character trial and error functions

Character duty Description
isalpha true if letter in alphabet
isdigit true if number from 0-9
isalnum true if letter in alphabet or numerical digit
islower true if lowercase letter
isprint true if printable character consisting of space
ispunct true if printable character other than digit, letter, or space
isupper true if uppercase letter
isspace true if character is whitespace (tab, vertical tab, space, or newline

All the these attributes have a solitary character parameter so you have the right to use them favor this