0
0
C++programming~10 mins

Arithmetic operators in C++ - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Arithmetic operators
Start
Read operands
Choose operator: +, -, *, /, %
Perform calculation
Store/Display result
End
The program starts by reading two numbers, then chooses an arithmetic operator to perform the calculation, and finally shows the result.
Execution Sample
C++
int a = 10;
int b = 3;
int sum = a + b;
int diff = a - b;
int prod = a * b;
int quot = a / b;
int mod = a % b;
This code calculates sum, difference, product, quotient, and remainder of two integers.
Execution Table
StepOperationOperandsResultExplanation
1Addition10 + 313Adds a and b, stores in sum
2Subtraction10 - 37Subtracts b from a, stores in diff
3Multiplication10 * 330Multiplies a and b, stores in prod
4Division10 / 33Divides a by b (integer division), stores in quot
5Modulo10 % 31Remainder of a divided by b, stores in mod
6End--All operations done
💡 All arithmetic operations completed and results stored.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5
a101010101010
b333333
sumundefined1313131313
diffundefinedundefined7777
produndefinedundefinedundefined303030
quotundefinedundefinedundefinedundefined33
modundefinedundefinedundefinedundefinedundefined1
Key Moments - 3 Insights
Why does division 10 / 3 give 3 instead of 3.333?
Because both a and b are integers, C++ does integer division which discards the decimal part. See step 4 in execution_table.
What does the modulo operator (%) do?
It gives the remainder after division. For 10 % 3, the remainder is 1 as shown in step 5.
Are the original variables a and b changed by these operations?
No, a and b keep their original values throughout, only new variables store results. See variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the result of the multiplication at step 3?
A30
B13
C7
D3
💡 Hint
Check the 'Result' column for step 3 in execution_table.
At which step does the modulo operation happen?
AStep 2
BStep 5
CStep 4
DStep 1
💡 Hint
Look for '%' operator in the 'Operation' column in execution_table.
If variable b was 4 instead of 3, what would be the new result of 10 % b?
A1
B0
C2
D3
💡 Hint
Modulo gives remainder: 10 divided by 4 leaves remainder 2.
Concept Snapshot
Arithmetic operators in C++:
+ addition
- subtraction
* multiplication
/ division (integer if both operands int)
% modulo (remainder)
Operands must be numbers; integer division truncates decimals.
Full Transcript
This example shows how arithmetic operators work in C++. We start with two integers a=10 and b=3. We add them to get 13, subtract to get 7, multiply to get 30, divide to get 3 (integer division), and find remainder 1 using modulo. Variables a and b remain unchanged. Each step performs one operation and stores the result in a new variable. Integer division discards decimals. Modulo gives the remainder after division.