I understand that a mod operator finds the remainder of two numbers. However, I am having trouble understanding the concept when the numbers are reversed. Meaning, a smaller number comes first in the operation.
int x = 4 % 3 ; // prints out 1
However, can someone explain this to me:
int y = 1 % 4 ; // prints out 1
int z = 2 % 3 ; // prints out 2
Thanks in advance!
Are you sure about the int y that prints out 2?
The int z though seems normal : 2= 0*3 + 2
int y = 1 % 4 should print 1 because: 1=0*4 + 1
It works the same as when a bigger number comes first, you just take the remainder of the division of the first one by the second one.