Comparison OperatorsComparison Operators

Comparison operators allow you to compare two or more values. The hardest part about learning comparison operators is remembering the order of the characters, for example, the character < or = comes first.

Here is a list of all comparison operators, some of which you have already met:

OperationOperatorExpression syntax
equality==a == b
inequality!=a != b
more>a > b
less<a < b
more or equal>=a >= b
less or equal<=a <= b

The program will show the truth of each expression, that is, if the expression is true, the program will show 1, and if the expression is false, it will show 0.



Comparison operators will be used for loops and branch operators.

Operation Priorities

It is very important to understand the sequence of operators.


Solve the example: 2+2*2 =? If your answer is 8, then do not despair, the author of this course also does not know mathematics well.

The increment/decrement operators have very high precedence, meaning they will be executed first. Next, come the division and multiplication operators, and lastly, the sum and difference operators.

Expression precedence can be emphasized with parentheses. For example, the expression

Maybe rewritten as:

Everything was clear?

Section 3. Chapter 4