Properties of Modulus operator
- Range of Results:
- The result of
a % b
will always be in the range[0, b-1]
. - If
a
is positive andb
is positive, the result will be positive. - If
a
is negative orb
is negative, the sign of the result depends on the programming language’s convention.
- The result of
- Division by Zero:
- Division by zero is undefined in mathematics. Similarly, the modulus operator by zero is usually undefined or throws an error in programming languages.
- Equality to Dividend:
- If
a
is less thanb
,a % b
will be equal toa
.
- If
Modulus Operator in Programming
The modulus operator, often represented by the symbol ‘%'
, is a fundamental arithmetic operator used in programming languages to find the remainder of a division operation between two numbers. It returns the remainder of dividing the first operand by the second operand.
Table of Content
- What is the Modulus Operator?
- Basic Syntax of Modulus Operator
- How Modulus operator works?
- Properties of Modulus operator
- Example to show Modulus operator
- Modulus Operator in C
- Modulus Operator in C++
- Modulus Operator in Java
- Modulus Operator in Python
- Modulus Operator in C#
- Modulus Operator in Javascript
- Uses or Application of Modulus Operator
- Performance Considerations of Modulus Operator