"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Sunday, 14 July 2019

Relational Operator

Relational Operator

      A relational operator is a symbol that is used to compare two values of the same type. The result of the comparison is True (or 1) or False (or 0). The relational operators are used to specify conditions in programs. The relational operators are also known as comparison operators.
      C-language provides six basic relational operators. These operators with symbols, meanings and with examples are given below. The variables 'a' , 'b', and 'c' are used in examples. Suppose, value of 'a' is 10, 'b' is 5 and 'c' is 10.


Operator
Meaning
Purpose
Example
==
Equal to
Return true if both values are equal; otherwise return false.
a == b return false
!=
Not Equal to
Return true if both values are different; otherwise return false.
a! = b return true
> 
Greater than
Return true if first value is greater; otherwise return false.
a > b return true
< 
Less than
Return true if first value is less than; otherwise return false.
a < b return false
>=
Greater than or Equal to
Return true if first value is greater than or equal to second; otherwise return false.
a >= c return true
<=
Less than or Equal to
Return true if first value is less than or equal to second; otherwise return false.
a <= c return true

Relational Expression

      An expression that contains two operands and one relational operator between these operands is called relational expression. The relational expression returns true (or 1) or false (or 0). The relational expression is used in conditional statement (or looping statements) as test condition. In C, true can be represented by any non-zero value while false can be represented by zero value.
      For example, a > b is a relational expression. It returns true if the value of 'a' is greater than 'b', otherwise it returns false. Suppose a = 6, b = 9 and c = 6. The relational expression and their output values are shown in the following table.


Relational Operator
Output
        a > c
        a <= c
           a < b
           a >= c
           a == b
           a != c
False
True
True
True
False
False


No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.