Saral Code logo
Saral Code
    HomeBlogTutorialsMCQs

No Related Topics Available


Comparison operators are used to compare two values in C++. These operators return a boolean value (either true or false) based on whether the comparison is true or false. Here are the six comparison operators in C++:

Equal to (==):

The equal to operator is used to check whether two values are equal. Here's an example:

C++
int a = 10;
int b = 5;
bool result = (a == b); // result will be false

Not equal to (!=):

The not equal to operator is used to check whether two values are not equal. Here's an example:

C++
int a = 10;
int b = 5;
bool result = (a != b); // result will be true

Greater than (>):

The greater than operator is used to check whether one value is greater than another. Here's an example:

C++
int a = 10;
int b = 5;
bool result = (a > b); // result will be true

Less than (<):

The less than operator is used to check whether one value is less than another. Here's an example:

C++
int a = 10;
int b = 5;
bool result = (a < b); // result will be false

Greater than or equal to (>=):

The greater than or equal to operator is used to check whether one value is greater than or equal to another. Here's an example:

C++
int a = 10;
int b = 5;
bool result = (a >= b); // result will be true

Less than or equal to (<=):

The less than or equal to operator is used to check whether one value is less than or equal to another. Here's an example:

C++
int a = 10;
int b = 5;
bool result = (a <= b); // result will be false

In all of these examples, the result variable will be a boolean value (either true or false) based on whether the comparison is true or false.

I hope this helps!