+ 3
I didn't really understand what "%" is doing?
E.g. why does x%3 output 0 if x=15? So what is % exactly doing? I didn't understand its function.
3 Answers
+ 9
% or the modulo operator returns the remainder of an equation.
ex. 22 / 3
Quotient: 7
Remainder: 1
So if you do 22 % 3, you will get the remainder which is 1.
and in the case of 15 % 3, there is no remainder or 0 as 5 * 3 = 15
+ 4
That's the modulo operator.
It returns the remainder of division.
5 % 5 = 0
7 % 5 = 2
+ 2
Thank you :)