C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs

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:









COMMENTS