Relational Operators in C Language


RELATIONAL OPERATORS



A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the relation is false, it returns value 0.


Here, in above top 3 has more priority than bottom 2 and if top 2 or bottom 2 come in same instruction/line then it's solve according to associative rule i.e left to right for example in program <,><=,>= is written then you should start solving it from left i.e first solve < then > and so on .

Rules--




Example :1

#include <stdio.h>
int main()
{
int a=5, b=5, c=10;
printf("%d = = %d =%d \n", a, b, a= = b); // true


printf("%d = = %d =%d \n", a, c, a= = c); // false


printf("%d > %d =%d \n", a, b, a> b); // false

printf("%d > %d =%d \n", a, c, a> c); // false


printf("%d < %d =%d \n", a, b, a < b); // false

printf("%d < %d =%d \n", a, c, a < c); // true


printf("%d != %d =%d \n", a, b, a! = b); // false

printf("%d ! = %d =%d \n", a, c, a! = c); // true


printf("%d > = %d =%d \n", a, b, a> = b); // true

printf("%d > = %d =%d \n", a, c, a> = c); // false


printf("%d < = %d =%d \n", a, b, a< = b); // true

printf("%d < = %d =%d \n", a, c, a< = c); // true

return 0;
}

Output


5 = = 5 = 1
5 = = 10 = 0
5 > 5 = 0
5 > 10 = 0
5 < 5 = 0
5 < 10= 1
5 ! = 5 = 0
5 ! = 10 = 1
5 > = 5 = 1
5 > = 10 = 0
5 < = 5 = 1
5 < = 10 = 1

Example :2






Output --  0


Note :-  In above example x=5>4>3  , according to associative rule ,first expression 5>4 solve and it's true so answer come in place of exression 5>4 is 1 ,now next expression solve i.e 1>3 and it's false so answer will 0.

Comments

Popular posts from this blog

Important Announcements(download all my book free)

O LEVEL- INTERNET TECHNOLOGY & WEB DESIGN

Call by Reference with Pointer in C Language part-4-a