Equal to (==) Comparison Operator
The “equal to” (==) operator is a comparison operator widely used in programming languages to determine whether two values or expressions are equal.
Example of Equal to (==) Comparison Operator:
Here are the example of Equal to (==) Operator in different language:
#include <iostream>
using namespace std;
int main()
{
int x = 5;
int y = 10;
// x == y returns true if x is equal to y else it
// returns false
if (x == y) {
cout << "x is equal to y" << endl;
}
else {
cout << "x is not equal to y" << endl;
}
return 0;
}
#include <stdio.h>
int main()
{
int x = 5;
int y = 10;
// x == y returns true if x is equal to y else it
// returns false
if (x == y) {
printf("x is equal to y\n");
}
else {
printf("x is not equal to y\n");
}
return 0;
}
public class Main {
public static void main(String[] args)
{
int x = 5;
int y = 10;
// x == y returns true if x is equal to y else it
// returns false
if (x == y) {
System.out.println("x is equal to y");
}
else {
System.out.println("x is not equal to y");
}
}
}
let x = 5;
let y = 10;
// x == y returns true if x is equal to y
// else it returns false
if (x == y) {
console.log("x is equal to y");
} else {
console.log("x is not equal to y");
}
x = 5
y = 10
# x == y returns true if x is equal to y else it returns false
if x == y:
print("x is equal to y")
else:
print("x is not equal to y")
Output
x is not equal to y
Comparison Operators in Programming
Comparison Operators in programming are used to compare values and determine their relationship, such as equality, inequality, greater than, less than, etc. They evaluate expressions and return a Boolean value (true or false) based on the comparison result, crucial for decision-making in conditional statements and loops.
Table of Content
- What is a Comparison Operator?
- Common Comparison Operators
- Equal to (==) Comparison Operator
- Not equal to (!=) Comparison Operator
- Greater than (>) Comparison Operator
- Greater than or equal to (>=) Comparison Operator
- Less than (<) Comparison Operator
- Less than or equal to (<=) Comparison Operator