HomeLinuxC Relational and Equality Operators

C Relational and Equality Operators


Operators are the primary basis of any programming language as they assist customers carry out mathematical and numerical operations on operands. With the assistance of those operators, the customers will be capable of function operands. There are several types of built-in operators in C: arithmetic, logical, relational, bitwise, equality, and others.

This text will talk about relational and equality operators within the C programming language.

C Relational and Equality Operators

Relational and Equality Operators are C operators used to check two values as they decide the relation between them. These operators embrace “equal to (=)”, “not equal to (!=)”, additionally known as Equality operators. Whereas additionally they embrace relational operators like “lower than (<)”, “higher than (>)”, and a mixture of each relational and equality operators like “lower than or equal to (<=)” and “higher than or equal to (>=)”.

Let’s talk about every operator intimately.

1: Equal to Operator (=)

The equal to (=) operator is a sort of equality operator utilized in a code to check the values. It compares two values in a code and returns True if each are equal.

2: Not Equal to Operator (!=)

The not equal to (!=) operator in C language compares the 2 values and returns the consequence as True if each values are usually not equal.

3: Lower than Operator (<)

This operator compares the 2 values and returns the assertion as True if the primary worth is lower than the second worth. In any other case, it considers it False.

4: Better than Operator (>)

That is one other relation operator that compares the 2 values and outputs the consequence to True if the primary worth is larger than the second worth.

5: Lower than or Equal to Operator (>=)

This operator checks the 2 values in a situation, and within the first case, it checks whether or not the primary worth is larger than the second worth; if it’s not, it checks whether or not each are equal. If any situation meets, you will note the output as True. In any other case, it outputs False.

6: Better than or Equal to Operator (>=)

That is one other helpful operator that checks the comparability of two values. If the 2 values meet any situation higher or equal to, it generates the consequence as True, in any other case, it considers the assertion as False.

Let’s comply with up with a easy instance beneath that pertains to all these operators mentioned above.

#embrace <stdio.h>

int foremost()

{

  int X =6, Y =10;

  // equal to

  if (X == Y)

printf(“X is the same as Yn);

  else

printf(“X and Y are usually not equaln);

  // not equal to

  if (X != Y)

printf(“X will not be equal to Yn);

  else

printf(“X is equal Yn);

  // lower than instance

  if (X < Y)

printf(“X is lower than Yn);

  else

printf(“X is larger than or equal to Yn);

  // higher than instance

  if (X > Y)

printf(“X is larger than Yn);

  else

printf(“X is lower than or equal to Yn);

  // lesser than equal to

  if (X <= Y)

printf(“X is lesser than or equal to Yn);

  else

printf(“X is larger than Yn);

  // higher than equal to

  if (X >= Y)

printf(“X is larger than or equal to Yn);

  else

printf(“X is lesser than Yn);

  return 0;

}

Within the above code, two numbers X and X are given. The code checks every situation one after the other. These circumstances which might be met will print on the output proven beneath:

Output

On this approach, you need to use these relational and equality operators in C.

Conclusion

Relational and Equality Operators are C operators used to check two values as they decide the relation between them. These operators embrace ”equal to (=)”, ”not equal to (!=)”, additionally known as Equality operators. Whereas additionally they embrace relational operators like lower than (<), extra important than (>) and a mixture of each relational and equality operators like lower than or equal to (<=) and higher than or equal to (>=).

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments