C Division Operator

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

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

Operator Symbol

The symbol of Arithmetic Division Operator is /.

Syntax

The syntax of Division Operator with two operands is

</>
Copy
operand1 / operand2

When this operator is given with operands of different numeric datatypes, the lower datatype is promoted to higher datatype.

Examples

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

main.c

</>
Copy
#include <stdio.h>

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

Output

Result : 4
Program ended with exit code: 0

In the following program, we take two float values in a, b, and find the division a / b using Division Operator.

main.c

</>
Copy
#include <stdio.h>

int main() {
    float a = 1.4;
    float b = 0.3;
    
    float result = a / b;
    printf("Result : %f\n", result);
    
    return 0;
}

Output

Result : 4.666667
Program ended with exit code: 0

In the following program, we take two numeric values of different datatypes, say an integer value in a, and a floating point value in b, and find the division a / b.

main.c

</>
Copy
#include <stdio.h>

int main() {
    int a = 2;
    float b = 0.3;
    
    float result = a / b;
    printf("Result : %f\n", result);
    
    return 0;
}

Output

Result : 6.666667
Program ended with exit code: 0

Since, int is the lower datatype and float is the higher datatype, the operation a / b promotes a to float datatype.

Conclusion

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