Relational operators in C

Relational Operators

Relational Operators are used to states the truth value of the expression. Result of these operators are either 1 (for true) or 0 (for false). There are six such operators in C language.
1.< (less than),
2.> (greater than),
3.<= (less than or equal to),
4.>= (greater than or equal to)
5.==(equal to),
6.!= (not equal to)

Four operators (<, >, <=, >=) have higher priority than the two operators(==, !=).
Example
int main()
{
int x;
x=5<3; printf(“%d”,x); return(0); }

Output is:
0
Explanation:
As the relation 5<3 is false, x will contain 0 as a result of the operation. Example int main()
{
int x;
x=5>4>3;
printf(“%d”,x);
return(0);
}

Output is:
0
Explanation:
5>4 results 1. so the expression becomes x=1>3 which is false, thus the result is 0.
If you want to learn more on relational operators watch this.

No comments:

Post a Comment

Featured Post

Core and Advance Python

                      Language Fundamentals