Shares
print sharing button Print
twitter sharing button Tweet
facebook sharing button Share
whatsapp sharing button Share
pinterest sharing button Pin
email sharing button Email
reddit sharing button Share
douban sharing button Share
arrow_left sharing button
arrow_right sharing button

C and C++ - Relational Operators

<<Previous

Next >>





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 DescriptionExample Return value
<less than4<5 1
>greater than4>5 0
<=less than equal to4<=51
>=greater than equal to4>=50
==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

<< Previous

Next >>




strcat() - String Concatenation        strcmp() - String Compare


strcpy() - String Copy        strlen() - String Length














C and C++ - Relational Operators

<<Previous

Next >>





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 DescriptionExample Return value
<less than4<5 1
>greater than4>5 0
<=less than equal to4<=51
>=greater than equal to4>=50
==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

<< Previous

Next >>






strncat() - String n Concatenation        strlwr() - String Lower       

strncmp() - String n Compare       strncpy() - String n Copy