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:

TOP Interview Coding Problems/Challenges

Learn PCB Designing: PCB DESIGNING TUTORIAL

 Recommended posts C Tips & Tricks, C++ Tips & Tricks Introduction to Linux (Its modes, Safety, Most popular Applications) Linux Best Distros of 2018 C programming optimization techniques Differences b/w C & Embedded C? Embedded C Interview Q. & A. C programming tips for Embedded Development Basic rules of writing a C program Important points (rules) to remember while writing C/C++ program Top 5 Websites for solving programming challenges Read more...

 Others... Computer G.K. (MCQ) Most viewed pages... Categories...

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