Learn about the Arithmetic, Relational and Equality operators. You'll also be able to write better code when you will know about operator precedence and a common bug made with the equality operator.

Like in any other programming language, in C, there are many arithmetic, relational, and logical operators we can use to write expressions that are made up of simpler basic types.

Arithmetic Operators

The following binary arithmetic operators can be used in C: +, -, *, / and the modulus operator %. When writing arithmetic expressions, we must always be aware of operator precedence, which is the order in which operators are applied when evaluating an expression.

For example 4+5*6 evaluates to 34, because the * operator has precedence over the + operator, and so the expression is evaluated as 4 + (5*6), not (4+5)*6. My strategy to deal with this is always to use brackets to denote the desired precedence in arithmetic expressions explicitly. So instead of writing:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy