Why is 0 mod 0 an error?

user541686 picture user541686 · Oct 15, 2013 · Viewed 17.8k times · Source

If I type:

int main() { return 0 % 0; }

I get back an error:

error C2124: divide or mod by zero

What is the reason behind this? Isn't the answer zero?

Answer

0x499602D2 picture 0x499602D2 · Oct 15, 2013

In mathematics, x mod 0 is undefined, hence the error.