Saturday 7 January 2012

Relational Operators

Relational operators are symbols that are used to test the relationship between two variables, or between a variable and a constant.
These operators are binary operators.
The test for equality, is made by means of two adjacent equal signs with no space separating them. 
‘C’ has six relational operators as follows:

>   greater than
<   less than
!=  not equal to
>= greater than or equal to
>= less than or equal to

These operators all fall within the same precedence group, which is lower than the unary and arithmetic operators. The associativity of these operators is left-to-right.

The equality operators ==and != fall into a separate precedence group. Their associativity is also from left-to-right.


Let us understand operations of these relational operaters with the help of an example: x=2, y=3, z=4.
x<y               true     1
(x+y) >=z     true     1
(y+z)>(x+7)  false    0
z!=4              false    0
y ==3            true    1
Here, true or false represents logical interpretation and they have values 1 and 0 respectively.
Example
main()
{
int a=5,b=7,c;
c=a<b;
printf("%d",c);

c=a<=b;
printf("%d",c);

c=a>b;
printf("%d",c);

c=a>=b;
printf("%d",c);

c=a==b;
printf("%d",c);

c=a!=b;
printf("%d",c);
}

1 comment:

  1. i am having a situation like a=a && b>c what is the meaning of it??

    ReplyDelete

host gator coupon