Home » C programming language

Equality Operators in C, C++ programming language



Learn: What are the equality operators in C, C++ programming language? In this articles I am going to write about two operators which are comes under the Equality Operators.

There are two operators which are known as Equality Operators:

  1. Equal To Operator (==)
  2. Not Equal To Operator (!=)

1) "Equal To" Operator (==)

It’s a binary operator and works on two operands, it returns 1 if value of both operands are equal else it returns 0.

Syntax:

Operand1 == Operand2

Tip: There should be a space between operands and operators.

Consider the example:

In this example, we have two variables (operands for the operator) "a" and "b" and the value of "a" is "10" and value of "b" is also "10".

#include <stdio.h>

int main()
{
    int a=10;
    int b=10;
    
    int result;
    
    result = (a==b);
    
    printf("result: %d\n",result);
    
    return 0;
}

Output

result: 1

2) "Not Equal To" Operator (!=)

It’s a binary operator and works on two operands, it returns 1 if value of both operands are not equal else it returns 0.

Syntax:

Operand1 != Operand2

Tip: There should be a space between operands and operators.

Consider the example:

In this example, we have two variables (operands for the operator) "a" and "b" and the value of "a" is "10" and value of "b" is also "10".

#include <stdio.h>

int main()
{
    int a=10;
    int b=10;
    
    int result;
    
    result = (a!=b);
    
    printf("result: %d\n",result);
    
    return 0;
}

Output

result: 0

Here is the list of C programs for your practices.

Some of the good programs based on Equality Operators with other relations operators:






Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.