0
0
Cprogramming~10 mins

Arithmetic operators - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Arithmetic operators
Start
Initialize variables
Apply +, -, *, /, %
Store results
Print results
End
This flow shows how arithmetic operators take variables, perform calculations, store results, and then output them.
Execution Sample
C
int a = 10;
int b = 3;
int sum = a + b;
int diff = a - b;
int prod = a * b;
int div = a / b;
int mod = a % b;
printf("%d %d %d %d %d", sum, diff, prod, div, mod);
This code calculates sum, difference, product, division, and remainder of two integers and prints the results.
Execution Table
StepOperationExpressionResultExplanation
1Additionsum = a + b1310 + 3 equals 13
2Subtractiondiff = a - b710 - 3 equals 7
3Multiplicationprod = a * b3010 * 3 equals 30
4Divisiondiv = a / b3Integer division 10 / 3 equals 3 (fraction discarded)
5Modulomod = a % b1Remainder of 10 divided by 3 is 1
6Printprintf(...)13 7 30 3 1Outputs all results separated by spaces
7End--Program finishes
💡 All arithmetic operations completed and results printed
Variable Tracker
VariableInitialAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
a10101010101010
b3333333
sumundefined131313131313
diffundefinedundefined77777
produndefinedundefinedundefined30303030
divundefinedundefinedundefinedundefined333
modundefinedundefinedundefinedundefinedundefined11
Key Moments - 3 Insights
Why does division of 10 / 3 give 3 instead of 3.333?
In C, dividing two integers results in integer division, which discards the decimal part. See execution_table step 4 where div = 3.
What does the modulo operator (%) do?
Modulo gives the remainder after division. In step 5, 10 % 3 equals 1 because 3 goes into 10 three times with remainder 1.
Are the original variables 'a' and 'b' changed by the operations?
No, 'a' and 'b' keep their initial values throughout. Only new variables store results, as shown in variable_tracker.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what is the value of 'prod'?
A7
B13
C30
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 the '%' operator in the 'Operation' column in execution_table.
If 'a' was 9 instead of 10, what would be the new value of 'mod'?
A0
B1
C2
D3
💡 Hint
Modulo is remainder of division; 9 % 3 equals 0, but check carefully.
Concept Snapshot
Arithmetic operators in C:
+ addition
- subtraction
* multiplication
/ integer division (fraction discarded)
% modulo (remainder)
Use with integers to calculate and store results.
Full Transcript
This example shows how arithmetic operators work in C. Variables a and b are set to 10 and 3. Then sum, difference, product, division, and modulo are calculated step-by-step. Division discards decimals because both operands are integers. Modulo gives the remainder after division. The original variables stay unchanged. Finally, all results are printed together.