Operators
Operators
(Operators)
Operator Description
== equal to
!= not equal to
< less than
<= less than and equal to
> greater than
>= greater than and equal to
• Each of the relational operators is a binary operator because it requires two operands.
Relational Operators and Simple Data Type
• The relational operators are used with all three simple data types.
• Examples :-
• Example:
string str1 = “Hello”;
string str2 = “Hi”;
string str3 = “Air”;
string str4 = “Bill”;
string str5 = “Big”;
Relational Operators and the string Type
• The variables of type string are compared character-by-character, starting with
the first character and using ASCII collating sequence.
• The character-by-character comparison continues until either a mismatch is
found or the last characters have been compared and are equal.
• Example:
string str1 = “Hello”;
string str2 = “Hi”;
string str3 = “Air”;
string str4 = “Bill”;
string str5 = “Big”;
ASCII Table
Relational Operators and the string Type
• If two strings of different lengths are compared and the character-by-character
comparison is equal until it reaches the last character of the shorter string, the
shorter string is evaluated as less than the larger string.
Logical operators and logical expressions
• C++ provides three logical operators.
Operator Description
• ! not
&& and
|| or
• Logical operators take only logical value as operand and yield only logical values (true or false) as
results.
The correct statement for this (0 <= num && num < = 10),