What does the modulo operator (%) do?

Prepare for the RECF Programming Test. Enhance your skills with flashcards and multiple-choice questions, each with hints and explanations. Get ready for your exam!

Multiple Choice

What does the modulo operator (%) do?

Explanation:
Modulo computes the remainder after dividing one number by another. When you divide a by b, you get a quotient (how many times b fits into a) and a remainder (what’s left). The expression a % b returns that remainder. For example, 7 % 3 is 1, because 3 goes into 7 twice with 1 leftover. Similarly, 9 % 3 is 0, since 3 fits perfectly into 9 with nothing left over. This is not the quotient, nor the sum, nor the product. Modulo is handy for tasks like checking if a number is even (n % 2 gives 0 for even numbers) or wrapping around indices in circular structures.

Modulo computes the remainder after dividing one number by another. When you divide a by b, you get a quotient (how many times b fits into a) and a remainder (what’s left). The expression a % b returns that remainder. For example, 7 % 3 is 1, because 3 goes into 7 twice with 1 leftover. Similarly, 9 % 3 is 0, since 3 fits perfectly into 9 with nothing left over. This is not the quotient, nor the sum, nor the product. Modulo is handy for tasks like checking if a number is even (n % 2 gives 0 for even numbers) or wrapping around indices in circular structures.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy