C

1. Binary Operators

These require two operands (numbers or variables) to perform a calculation.

OperatorOperationExample (a=10,b=3)Result
+Addition$a + b$$13$
-Subtraction$a - b$$7$
*Multiplication$a * b$$30$
/Division$a / b$$3$ (Integer division)
%Modulus (Remainder)$a \% b$$1$

2. Unary Operators

These operators act on a single operand. They are frequently used in loops, which you will cover later in the curriculum.

  • Increment (++): Increases the value of a variable by 1.

  • Decrement (--): Decreases the value of a variable by 1.

Note on Division: In C, if you divide two integers (e.g., $5 / 2$), the result will be an integer ($2$), not a decimal ($2.5$). To get a decimal result, at least one operand must be a float or double.

3. The Modulus Operator (%)

The modulus operator is unique because it returns the remainder of a division. It is incredibly useful in programming for tasks like:

  • Checking if a number is even or odd (x % 2 == 0).

  • Finding the last digit of a number (x % 10).

  • Keeping a value within a certain range (used often in circular buffers in embedded systems).

Precedence and Associativity

When multiple operators appear in one expression (e.g., $10 + 5 * 2$), C follows a specific order:

  1. Multiplication, Division, and Modulus have higher priority.

  2. Addition and Subtraction have lower priority.

  3. If operators have the same priority, they are evaluated from left to right.

Upcoming Course
Upcoming Course
Learn More
Instructor Tips
Instructor Tips
View Tips
Join Community
Join Community
Join Now