Nearby lessons
28 of 124C - Assignment Operators
Assignment Operators is one of the foundational topics in C programming. This lesson explains Assignment Operators (= += -= *= /= %=) and Program: every shortcut operator with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
Assignment Operators (= += -= *= /= %=)
The = assigns a value. The shortcut operators combine assignment with an operation — a += 5 means a = a + 5.
| Operator | Means | Example (a=10) |
|---|---|---|
| = | assign | a = 5; → a is 5 |
| += | a = a + value | a += 5; → a is 15 |
| -= | a = a - value | a -= 5; → a is 5 |
| *= | a = a * value | a *= 2; → a is 20 |
| /= | a = a / value | a /= 5; → a is 2 |
| %= | a = a % value | a %= 3; → a is 1 |
Program: every shortcut operator
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
1 QuestionsProgress: 0 / 1