# C and C++ - Relational Operators

The relational operators are used to distinguishes between two values depending upon their relations. This operators provide relationship between two expressions. The relational operators always return the result as a boolean values(true or false). If the relation is true, then it returns value 1. Otherwise it returns zero for false relation.

Operator | Description | Example | Return value |
---|---|---|---|

< | less than | 4<5 | 1 |

> | greater than | 4>5 | 0 |

<= | less than equal to | 4<=5 | 1 |

>= | greater than equal to | 4>=5 | 0 |

== | equal to | 4==5 | 0 |

!= | not equal to | 4!=5 | 1 |

## Example C Program using Relational Operators

Operators used in C are useful in C++ programming as well

#include <stdio.h> #include <conio.h> int main() { int a=20; int b=35; if(a>b){ printf("The value of a is greater than b\n"); } else{ printf("The value of a is not greater than b\n "); } if(a<b){ printf("The value of a is less than b \n "); } else{ printf("The value of a is not less than b \n "); } if(a<=b){ printf("The value of a is less than and equal to b \n "); } else{ printf("The value of a is not less than and not equal to b \n "); } if(a>=b){ printf("The value of a is greater than and equal to b \n "); } else{ printf("The value of a is not greater than and not equal to b \n "); } if(a==b){ printf("The value of a is equal to b \n "); } else{ printf("The value of a is not equal to b \n "); } if(a!=b){ printf("The condition is true \n "); } else{ printf("The condition is false \n "); } return(0); }

Output:

The value of a is not greater than b The value of a is less than b The value of a is less than and equal to b The value of a is not greater than and equal to b The value of a is not equal to b The conditon is true