×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

Equality Operators in C, C++ programming language

Last Updated : December 17, 2025

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.

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.

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:

Equality Operators in C/C++ Exercise

Select the correct option to complete each statement about equality operators in C/C++ programming language.

  1. Which operator is used to check whether two values are equal in C/C++?
  2. What will be the result of the expression 5 == 10 in C/C++?
  3. Which equality operator returns true when two operands are not equal?

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.