What does the modulus operator % do?

Q4. What does the modulus operator % do? What will be the result of 7.2%2.1 and 8%3?

Ans. The % operator finds the modulus of its operand relative to the second. That is, it produces the remainder of dividing the first by the second operand.

While using modulus operator both operands must be integer types.

So, 7.2%2.1 will produce an error “Illegal use of floating type”.

8%3 will produce 2 as result.

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: