Search code examples
c++visual-c++mathmodulodivide-by-zero

Why is 0 mod 0 an error?


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?


Solution

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