Relational Operator

  • Relational operator is Binary, it needs two operands to perform the task.
  • It will give output as a 0 (False) and 1 ( True).
  • Both sides of the relational operator should be constant or a variable.
  • It will not modify the operands.

Example :

10 < 20;

i > j;

i > 20;

20 > j;

 

 

Code:

main()

{

int i = 10,j = 20 , k;

printf(“i = %d  j = %d  k = %d”,i , j , k);

k = i < j ;

printf(“i = %d  j = %d  k = %d”,i , j , k);

}

  • output of above program is i = 10, j = 20 , k = 1

 

So, now I am writing some programs below, try to do them and comment your output.

 

  1. main()

{

int i = 10,j = 20 , k;

printf(“i = %d  j = %d  k = %d”,i , j , k);

k = i < j + 20;

printf(“i = %d  j = %d  k = %d”,i , j , k);

}

 

2.main()

{

int i = 10,j = 20 , k;

printf(“i = %d  j = %d  k = %d”,i , j , k);

k = (i < j) +20;

printf(“i = %d  j = %d  k = %d”,i , j , k);

}

 

3. main()

{

int i = 10,j = 20 , k;

printf(“i = %d  j = %d  k = %d”,i , j , k);

k = i != j;

printf(“i = %d  j = %d  k = %d”,i , j , k);

}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: