What's the difference between “mod” and “remainder”?

songhir picture songhir · Dec 3, 2012 · Viewed 114.2k times · Source

My friend said that there are differences between "mod" and "remainder".

If so, what are those differences in C and C++? Does '%' mean either "mod" or "rem" in C?

Answer

David Schwartz picture David Schwartz · Dec 3, 2012

There is a difference between modulus and remainder. For example:

-21 mod 4 is 3 because -21 + 4 x 6 is 3.

But -21 divided by 4 gives -5 with a remainder of -1.

For positive values, there is no difference.