Nearby lessons

27 of 124

C - 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.

OperatorMeaningExampleResult
+Addition5 + 27
-Subtraction5 - 23
*Multiplication5 * 210
/Division5 / 22 (integer division)
%Modulo (remainder)5 % 21
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
CCode Cell
1#include <stdio.h>
2 
3void main()
4{
5 int a = 7, b = 2;
6 
7 printf("a = %d, b = %d\n", a, b);
8 printf("Addition : %d\n", a + b); // 9
9 printf("Subtraction : %d\n", a - b); // 5
10 printf("Multiplication : %d\n", a * b); // 14
11 printf("Division (int) : %d\n", a / b); // 3 (decimal dropped)
12 printf("Remainder (%%): %d\n", a % b); // 1
13 printf("Division (float): %.2f\n", 7.0 / 2); // 3.50
14}
Output

a = 7, b = 2
Addition       : 9
Subtraction    : 5
Multiplication : 14
Division (int) : 3
Remainder (%): 1
Division (float): 3.50
      
📝 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 Questions
Progress: 0 / 3