Python Arithmetic, Modulo & Increment Operators
C++ provides a full suite of mathematical operators: addition (+), subtraction (-), multiplication (*), division (/), modulo remainder (%), and fast increment/decrement (++ and --). Watch out for integer division!
"Integer division (7 / 2) is like cutting a physical pizza between 2 people without fractional slices—you both get 3 whole slices, and the remaining 1 slice is discarded into the modulo trash bin (7 % 2 = 1)."
Deep Dive: How It Works
Basic Arithmetic: +, -, *, /, % (modulo).
The Integer Division Trap: In C++, dividing two integers drops the decimal completely: 7 / 2 results in 3, NOT 3.5! To get 3.5, at least one number must be a float or double (7.0 / 2).
Modulo Operator (%): Returns the integer remainder after division. 10 % 3 = 1. Perfect for checking if a number is even (num % 2 == 0).
Increment & Decrement: count++ increases by 1; count-- decreases by 1.
Compound Assignment: x += 5 is shorthand for x = x + 5 (also -=, *=, /=).
Syntax Blueprint
int sum = 10 + 5; // 15 int div = 7 / 2; // 3 (truncated!) double exact = 7.0/2; // 3.5 int rem = 7 % 2; // 1 (remainder) x++; // Adds 1
Use 7.0 for decimal division and % for integer remainders.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Writing double result = 5 / 2; and wondering why result is 2.0Why it happens: 5 / 2 evaluates as integer math FIRST (yielding 2), and is then cast to 2.0.
How to fix: Write double result = 5.0 / 2; to trigger floating-point division.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Calculate rectangle area and perimeter
Declare int width = 8; and int height = 5;
Calculate int area = width * height; and int perimeter = 2 * (width + height);
Print "Area: 40 | Perimeter: 26".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.