The modulo operator (%) in C/C++ returns the remainder of a division between two integers. It is useful for operations where the remainder is needed, such as determining even/odd numbers or cyclic operations.
Syntax:
\text{result} = \text{a} \% \text{b};
Examples:
1. Example 1:
10 \% 3 = 1
2. Example 2:
8 \% 2 = 0
Use Cases:
Even/Odd Check:
\text{if} (\text{num} \% 2 == 0) \text{ // num is even}
The modulo operator is only applicable to integer types, and the divisor (b) must not be zero to avoid a runtime error.