+ 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.

20th Oct 2017, 10:03 AM
Rebecca Tessmer
Rebecca Tessmer - avatar
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
20th Oct 2017, 10:10 AM
Cool Codin
Cool Codin - avatar
+ 4
That's the modulo operator. It returns the remainder of division. 5 % 5 = 0 7 % 5 = 2
20th Oct 2017, 10:19 AM
Boris Batinkov
Boris Batinkov - avatar
+ 2
Thank you :)
20th Oct 2017, 10:12 AM
Rebecca Tessmer
Rebecca Tessmer - avatar