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 and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.