+ 1
What is the meaning of %
4 Answers
+ 4
Modulus gives the remainder of the division of one number by another.
7 % 5
This would return 2 due to the fact that 5 goes into 7 once and then gives the 2 that is left over
Note the difference in case of negative numbers-
x = 5 % (-3);
y = (-5) % (3);
z = (-5) % (-3);
+ 3
The '%' symbol is for modulus. Modulus is used to find the remainder of a division. For example:
9 % 4 = 1
8 % 2 = 0
15 % 8 = 7
+ 2
Modular -- It's related to division, but instead you get the remainder
In normal integer division the remainder is cut off example:
10/3 = 3 (%1)
5/3 = 1 (%2)
But if we use the mod operator we cut the main part of the number off and only keep the remainder:
10%3 = 1
5%3 = 2
0
it's a Remainder