Modulus Operator (%)

The Modulus Operator placed between two operands forms an expression which returns the difference of a subtraction from the first operand of the largest whole number multiple of the second operand.

For integer operands, the expression evaluates to an integer:

           int a = 17, b = 3, c = 0;
           c = a % b;    // c == 2    (17 - 3 * 5)

For floating point operands, the expression evaluates to a floating point number:

           double a = 15.5, b = 3.2, c = 0;
           c = a % b;    // c == 2.7  (15.5 - 3.2 * 4)

Copyright © 2003 The Stevens Computing Services Company, Inc.  All rights reserved.