VOOZH about

URL: https://www.geeksforgeeks.org/cpp/comparison-operators-in-programming/

⇱ Comparison Operators in Programming - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Comparison Operators in Programming

Last Updated : 21 Mar, 2024

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.

Comparison Operator is an operator that compares two operands and return true if the comparison evaluates to true otherwise, it returns false. They are important in programming, as they help us to compare values and expressions. The return value of a comparison is either true or false. 

  • Equality Operator (==).
  • Inequality Operator (!=)
  • Greater Than Operator (>)
  • Less Than Operator (<)
  • Greater Than or Equal To Operator (>=)
  • Less Than or Equal To 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:


Output
x is not equal to y

The "not equal to" (!=) operator is a comparison operator used in programming languages to determine whether two values or expressions are not equal.

Example of Not equal to (!=) Comparison Operator:

Here are the example of Not equal to (!=) Operator in different language:


Output
x is not equal to y

The "greater than" (>) operator is a comparison operator used in programming languages to determine whether the value or expression on the left of the operand is greater than the value or expression on the right.

Example of Greater than (>) Comparison Operator:

Here are the example of Greater than (>) Operator in different language:


Output
x is not greater than y

The "greater than or equal to" (>=) operator is a comparison operator used in programming languages to determine whether the value or expression on the left of the operand is greater than or equal to the value or expression on the right.

Example of Greater than or equal to (>=) Comparison Operator:

Here are the example of Greater than or equal to (>=) Operator in different language:


Output
x is greater than or equal to y

The "less than" (<) operator is a comparison operator used in programming languages to determine whether the value or expression on the left of the operand is less than the value or expression on the right.

Example of Less than (<) Comparison Operator:

Here are the example of Less than (<) Operator in different language:


Output
x is less than y

The "less than or equal to" (<=) operator is a comparison operator used in programming languages to determine whether the value or expression on the left of the operand is less than or equal to the value or expression on the right.

Example of Less than or equal to (<=) Comparison Operator:

Here are the example of Less than or equal to (<=) Operator in different language:


Output
x is less than or equal to y

Comparison operators are like tools that programmers use to compare things in their code. They help decide if something is true or false, which is super important for making decisions in programs. By knowing how to use these comparison operators properly, programmers can write code that works better and is easier to manage, no matter what kind of programming they're doing.

Comment
Article Tags:
Article Tags: