Jump to content

C++ Lessons : 9.2. Comparison Operators


quix
 Share

Recommended Posts

  • Manager

Comparison Operators

Comparison operators are used to compare two values (or variables). This is important in programming, because it helps us to find answers and make decisions.

The return value of a comparison is either 1 or 0, which means true (1) or false (0). These values are known as Boolean values, and you will learn more about them in the Booleans and If..Else chapter.

In the following example, we use the greater than operator (>) to find out if 5 is greater than 3:

Example

int x = 5;
int y = 3;
cout << (x > y); // returns 1 (true) because 5 is greater than 3

A list of all comparison operators:

Operator

Name

Example

 

==

Equal to

x == y

 

!=

Not equal

x != y

 

Greater than

x > y

 

Less than

x < y

 

>=

Greater than or equal to

x >= y

 

<=

Less than or equal to

x <= y

 

 

1.png.56210348f845fad9f2d8f843d77e3c16.png

Click! : adelinrzo

Click! quiixx.

Click! : raizo

 

Guardian of Leaks!

 

image.png.3ca1bf60c26a3523b93df92ea8521802.png (24.01.2023)

image.png.990bdf55e8ebaad7e92cc11967598b8d.png (12.03.2023)

image.png.25e5d76f6f7de46f49423812d3d500a3.png (30.03.2023)

Link to comment
Share on other sites

  • quix locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...