Math Fundamentals18 sections · 814 units
Open in Course

The Modulo Operator

Getting the remainder

When you divide 77 by 33, you get 22 with a remainder of 11. The modulo operator gives you that remainder: 7mod3=17 \bmod 3 = 1.

In code, you write this as 7%37 \% 3. The %\% symbol is the modulo operator in most languages. It shows up everywhere: checking even/odd numbers, cycling through arrays, hashing, and more.

Think of modulo as "what's left over after division." If you have 77 cookies and give 33 to each person, you have 11 cookie left. That's 7mod37 \bmod 3.