mod.cpp

Most of the time that computer scientist use the mod operator, both operands are positive. But the operator is defined for negative values as well. Notice that the left hand operator may be 0 but that it is a runtime error to have a 0 as the right hand operand.

#include <iostream>
using namespace std;

int main()
{
	cout << 11 % 4 << endl;
	cout << -11 % 4 << endl;
	cout << 11 % -4 << endl;
	cout << -11 % -4 << endl;

	cout << endl;

	cout << 0 % 4 << endl;
	cout << 0 % -4 << endl;

	return 0;
}
Output:
3
-3
3
-3

0
0