C Modulus Operator

In C Programming, Modulus Operator is used to find the remainder from division of a number by another number. The operator takes two operands as inputs and returns the remainder of division of first operand by the second operand.

In this tutorial, we shall learn about Arithmetic Modulus Operator and its usage with examples.

Operator Symbol

The symbol of Arithmetic Modulus Operator is %.

Syntax

The syntax of Modulus Operator with two operands is

</>
Copy
operand1 % operand2

Operands must of integer datatype.

Examples

In the following program, we take two integers in a, b, and find the remainder of division of a by b using Modulus Operator.

main.c

</>
Copy
#include <stdio.h>

int main() {
    int a = 10;
    int b = 4;
    
    int result = a % b;
    printf("Result : %d\n", result);
    
    return 0;
}

Output

Result : 2
Program ended with exit code: 0

Conclusion

In this C Tutorial, we learned what Arithmetic Modulus Operator is and how to use it to find remainder of the division of a number by another number with examples.