Nearby lessons
27 of 124C - Arithmetic Operators
Arithmetic Operators is one of the foundational topics in C programming. This lesson explains Arithmetic Operators (+ - * / %) and Program: all five arithmetic operators with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Arithmetic Operators (+ - * / %)
These do the basic maths. First see the full table, then run the complete program.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Addition | 5 + 2 | 7 |
| - | Subtraction | 5 - 2 | 3 |
| * | Multiplication | 5 * 2 | 10 |
| / | Division | 5 / 2 | 2 (integer division) |
| % | Modulo (remainder) | 5 % 2 | 1 |
Trainer's Note: Integer division trap: 5 / 2 gives 2, not 2.5, because both are integers — C drops the decimal part. If you want 2.5, make at least one operand a float: 5.0 / 2 or 5 / 2.0. The % operator gives the remainder and works only on integers.
Program: all five arithmetic operators
Example02
📝 Key Takeaways
- Operators: arithmetic (+ - * / %), relational (== != < > <= >=), logical (&& || !), assignment (= += -= *= /= %=), ++ --, ternary ?:.
- Each operator family has its own complete program — copy and run one at a time.
- Integer division drops decimals: 5/2 = 2; use 5.0/2 for 2.5.
- % gives the remainder and works only on integers.
- a++ uses then increases; ++a increases then uses.
- Ternary: condition ? value1 : value2.
- Use brackets to control the order of evaluation.
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3