There three main ways things can happen when two things are compared.
Let’s call the two things A and B.
A could be equal to B.
A could be greater than B.
A could be less than B.
A commonly used test is ” == ” or Equal To. In C, there is a difference between ” = ” and ” == ”
The single “equal-sign” is for assigning values to a variable:
means that the variable apple has been assigned the value of 3.
is asking if the value of apple is equal to 3 which is either true or false.
Here’s a simple example of the equals:
3==3 is true.
3 is equal to 3.
3==5 is false.
3 is NOT equal to 5.
You can think of the > as a mouth trying to eat the bigger of the two.
There is no better way of showing this than an example.
5 > 3 is true.
5 is greater than 3.
3 > 5 is false.
3 is NOT greater than 5.
If the value on the right is the bigger of the two being compared, then the symbol < is used and is read as less than.
Again, examples are the best way to explain how it works.
3 < 5 is true.
3 is less than 5.
5 < 3 is false.
5 is NOT less than 3.