Relational Operators


C# Operators

In C#, operators are symbols that represent the operation that the programme must execute on the operands. They can, for example, be used to evaluate a variable or to execute an action on a variable in order to create a valid expression.

Arithmetic operators, Relational operators, Assignment operators, Logical operators, Unary operators, and more operators are available in C#. In this lesson, we'll go over some of the most essential operators and how to use them.

The table below lists all of the relational operations provided by the C programming language. Assume variable A has a value of 10 and variable B has a value of 20.

Operator Description Example
== Checks whether two operands have the same value. If the answer is yes, the condition is fulfilled. (A == B) is not true.
!= Checks whether two operands have the same value. The condition becomes true if the values are not equal. (A != B) is true.
> If the left operand's value is greater than the right operand's value, the condition is true. The condition becomes true if the answer is yes. (A > B) is not true.
< Checks whether the left operand's value is smaller than the right operand's value. If the answer is yes, the condition is fulfilled. (A < B) is true.
<= Checks whether the left operand's value is greater than or equal to the right operand's value. If the answer is yes, the condition is fulfilled. (A <= B) is true
>= Checks whether the left operand's value is less than or equal to the right operand's value. If the answer is yes, the condition is fulfilled. (A <= B) is true.

Equal To Operator (==)

  • It compares two operands and returns 1 if they are equal or the same, and 0 if they are not.
  • Syntax
  • Opr1 is equal to Opr2.
  • Let's write a programme in C that compares the values of the operands using the double equal to operator (==).
#include stdio.h> in Program1.c int main #include math.h> () { int a = 5; int b = 10; int c = 20; int d = 20; int e = 20; // Use the Equal To Operator printf (" a == b: percent d", (a == b)); if (a == b) printf ("n percent d is equal to percent d", a, b); if (a == b) printf ("n percent d is not equal to percent d", a, b); if (a == b) printf ("n percent d is not equal to percent d", a); // Use Equal To Operator printf (" \n x == y : %d", (x == y)); if (a == b) printf (" \n %d is equal to %d", x, y); else printf ("\n %d is not equal to %d", x, y); return 0; }