Relational Operators

Relational Operators checks a condition (or their combinations) and returns a Boolean Value according to it , True (1) and False (0).
Following table shows all the relational operators supported by C language.



OperatorsWhat They Do ..Precedence
< Gives a Boolean value '1' in cases of checked no. being less and '0' in all other cases.1
<=Gives value '1' where checked no. is equal or less , otherwise '0'.1
>Gives a Boolean Value '1' in cases of checked no. being more and '0' in all other cases.1
>=Gives value '1' where checked no.is equal or more , otherwise '0'.1
==It checks the equality of characters.2
!=Gives value '1' where checked no. is Not Equal , otherwise '0'. 2



Syntax for Less Than :

[variable\constant] < [variable\constant]

 

C Example


#include<stdio.h>

int main() {

	int a,b,c,d,e,f,g;

	a=10;
	b=11;
	f=11;
	e=12;
	c=(a<b);
	// (a<b) returns a BOOLEAN value,i.e, 0 or 1 .....(1 here) 

	d=(f<b);
	// (a<b) returns a BOOLEAN value,i.e, 0 or 1 .....(0 here) 

	g=(e<b);
	// (a<b) returns a BOOLEAN value,i.e, 0 or 1 ..... (0 here)

	printf("a=%d,b= %d,f=%d,e=%d",a,b,f,e);
	printf("\n\n c=%d , d=%d , g=%d",c,d,g);

	return 0;
}

Output
a=10,b= 11,f=11,e=12
 c=1 , d=0 , g=0
 



Syntax for Less Than Equal To :

[variable\constant] <= [variable\constant] 

C Example

#include<stdio.h>

int main() {

	int a,b,c,d,e,f,g;

	a=1;

	b=11;

	f=11;

	e=12;

	c=(a>=b);

	// (a>=b) returns a BOOLEAN value,i.e, 0 or 1 .....(0 here) 

	d=(f>=b);

	// (a>=b) returns a BOOLEAN value,i.e, 0 or 1 .....(1 here) 

	g=(e>=b);

	// (a>=b) returns a BOOLEAN value,i.e, 0 or 1 ..... (1 here)

	printf("a=%d,b= %d,f=%d,e=%d",a,b,f,e);

	printf("\n\n c=%d , d=%d , g=%d",c,d,g);

	return 0;

}

 

Output
a=10,b= 11,f=11,e=12

c=0 , d=1 , g=1



Syntax for More Than :

[variable\constant] > [variable\constant] 

C Example

#include<stdio.h>

int main() {

	int a,b,c,d,e,f,g;

	a=10;

	b=11;

	f=11;

	e=12;

	c=(a>b);

	// (a>b) returns a BOOLEAN value,i.e, 0 or 1 .....(0 here) 

	d=(f>b);

	// (a>b) returns a BOOLEAN value,i.e, 0 or 1 .....(0 here) 

	g=(e>b);

	// (a>b) returns a BOOLEAN value,i.e, 0 or 1 ..... (1 here)

	printf("a=%d,b= %d,f=%d,e=%d",a,b,f,e);

	printf("\n\n c=%d , d=%d , g=%d",c,d,g);

	return 0;

}

Output
a=10,b= 11,f=11,e=12
c=0 , d=0 , g=1
 



Syntax for More Than Equal To :

[variable\constant] >= [variable\constant] 

C Example

#include<stdio.h>

int main() {

	int a,b,c,d,e,f,g;

	a=10;

	b=11;

	f=11;

	e=12;

	c=(a>=b);

	// (a>=b) returns a BOOLEAN value 

	d=(f>=b);

	// (a>=b) returns a BOOLEAN value 

	g=(e>=b);

	// (a>=b) returns a BOOLEAN value 

	printf("a=%d,b= %d,f=%d,e=%d",a,b,f,e);

	printf("\n  c=%d , d=%d , g=%d",c,d,g);

	return 0;

}
 

Output
 [variable\constant] == [variable\constant] 

C Example

#include<stdio.h>

int main() {

	int a,b,c;

	a=10;

	b=11;

	c=(a==b);

	// (a==b) returns a BOOLEAN value,i.e, 0 or 1 ..... 

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

}

Quantitative Aptitude
Reasoning
Programming
Interview