Thursday, April 7, 2016

Relational Operators

 Relational Operators   

relational operators

An operator is a symbol or letter used to indicate a specific operation on variables or values in a program. In order to carry out a comparison between two expressions (values/variables) one needs to use the relational operators. ANSI C++ standards specify that the result of a relational expression is binary. That means that the result of a comparison operation is either ‘True’ or ‘False’. Relational Operators are generally used in control structures and loops which we will study in later chapters. A list of relational operators supported in C++ are  given

<   Less than                        A<B    A is less than B 
_________________________________________________________________________________

>  Greater than                    A.>B   A is greater than B 
_________________________________________________________________________________

<=   Less than or equal to   A<=B   A is less than or equal to B 
_________________________________________________________________________________

>=   Greater than or equal to   A>=B   A is greater than or equal to B 
_________________________________________________________________________________

!=   Not equal to   A != B  A is not equal to B 
________________________________________________________________________________

==  Equality     A == B   

Compares the two variables ‘A’ and ‘B’ and checks for equality between these variables. If the variables seem to have equal values stored in them then the expression returns the integer value ‘1’ otherwise it returns the integer value ‘0’.  
Note: The values ‘1’ and ‘0’ are not any random values but are ‘Boolean digits’ where ‘1’ corresponds to the expression being true and ‘0’ corresponds to the expression being false.

No comments:

Post a Comment