0

The % Operator

Hey, I just can’t get my head around what the % operator is supposed to mean. I understand dividing and that sometimes it has a remainder, but how does this even work? How do you know what it will return? Also, do people even use this operator when programming?

20th Jan 2022, 5:11 PM
Apokvund
Apokvund - avatar
1 Respuesta
+ 4
The % operator returns the integer remainder of a division. One use case is, for example, determining if a number is odd or even. If we try 5 % 2, there will be a remainder of 1, hence 5 is odd. If we try 4 % 2 the remainder is 0, hence 4 is even.
20th Jan 2022, 5:16 PM
Lisa
Lisa - avatar