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?
1 Answer
+ 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.