Integer division / truncation
What you'll learn: How C handles division when using whole numbers and why the remainder disappears.
In everyday life, if you split 7 cookies between 2 people, you expect each person to get 3.5 cookies. However, in C, if you ask the computer to calculate 7 / 2 using integers, it will give you exactly 3. It doesn't round up to 4, and it doesn't keep the decimal. It simply throws the fractional part away.
The "Chop" Rule
This behavior is called truncation. Think of the division operator / as a lumberjack. When you divide two integers, the computer calculates the result, looks at the decimal point, and "chops off" everything to the right of it.
Even if the result is 0.99, C will truncate it to 0. It doesn't care how close the number is to the next whole number; it only cares about the integer part. This happens because an int variable is a container specifically designed to hold whole numbers only—it lacks the "internal plumbing" to store anything after a decimal point.
Seeing it in code
When both numbers in your division are integers, C assumes you want an integer result.
#include <stdio.h>
int main() {
int cookies = 7;
int people = 2;
int perPerson;
// Even though the math is 3.5, the .5 is discarded
perPerson = cookies / people;
printf("Each person gets %d full cookies.\n", perPerson);
// Another example: 19 divided by 10 is 1.9
int result = 19 / 10;
printf("19 / 10 becomes %d\n", result); // Output will be 1
return 0;
}
Why does this matter?
Truncation can lead to unexpected "hidden bugs" in your logic. For example, if you are trying to calculate a percentage by doing (3 / 4) * 100, C will calculate 3 / 4 as 0 first. Then, 0 * 100 is still 0.
To get a decimal result (like 3.5), at least one of the numbers in your division must be a floating-point type (like float or double). But as long as you are working strictly with int types, remember: the remainder isn't rounded—it is deleted.
Key takeaway
Integer division in C always "chops off" the decimal part, returning only the whole number result.