## What is a Division Operator?

We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:

**÷** and ** /**

Division in computer programming is more than finding a quotient and a remainder. There are different types of division, and different data types—which we’ll now learn about.

In computer programming, the division operator is a forward slash. The numbers or variables on either side of the slash are called the operands. In the expression “a/b”:

*a*is the left operand- the slash is the division operator
*b*is the right operand

The **division** **operator** in a computer programming language is a symbol with a defined function. This operator tells the compiler or interpreter to perform a division operation. The operator divides the left operand by the right operand and gives only the quotient as the result.

## How does Division Operator Work?

Data type | Size in bytes | Range |

int | 2 | -32,768 to 32,767 |

unsigned int | 2 | 0 to 65,535 |

short int | 1 | -128 to 127 |

unsigned short int | 1 | 0 to 255 |

long int | 4 | -2,147,483,648 to 2,147,483,647 |

unsigned long int | 4 | 0 to 4,294,967,295 |

In this article, we’ll learn about the division operator used in computer programming languages. Let’s first look at the basic types of division operations in computer programming:

To understand integer division and float division, we need to know about the various data types used in programming languages. The primary or fundamental data types are integer type, floating point type, character type and void.

Here, we will only look at integer types and floating-point types.

The **integer data type** allows the storage of whole numbers. There are six integer data types.

The size and range of each of these data types in a 16-bit processor are listed in the following table. Note that these values can vary among compilers:

The **float data type** allows the storage of real numbers. There are three float data types. The size and range of each of these data types in a 16-bit processor are listed in the following table. Note that, as with integer data types, these values can vary among compilers:

Data type | Size in bytes | Range | Precision |

float | 4 | 3.4E-38 to 3.4E+38 | Up to 6 decimal places |

double | 8 | 1.7E-308 to 1.7E+308 | Up to 15 decimal places |

long double | 10 | 3.4E-4932 to 1.1E+4932 | Up to 19 decimal places |

In integer division, both operands are of the integer data type. The division operation involves an integer type dividend divided by an integer type divisor to produce an integer type quotient.

Consider this division problem: You want to distribute 92 candy canes equally among eight children. How many candy canes can each child get? The answer is 11, even though there is a remainder when 92 is divided by 11.

That’s what integer division operator does; it only gives the quotient.

The following C++ code segment demonstrates this:

#include <iostream>

using namespace std;

int main()

{

` `

int num1 = 37;

` `

int num2 = 8;

` `

int quotient = num1 / num2;

` `

cout << quotient;

return 0;

}

This code, compiled using a standard C++ compiler, will result in 11 as the output.

In the above example, variables “a”, “b” and “c” are all of the integer data type. Here:

- “num1”—which we call the dividend—is the left operand for the division operation.
- “num2”—which we call the divisor—is the right operand for the division operation.
- The result of the operation gives a value, or quotient, that is stored in the variable “quotient.”

This is how we can write it in C language:

# include <stdio.h>

int main()

{

` `

int num1 = 92;

` `

int num2 = 8;

` `

int quotient = a / b;

` `

printf ("%d",c);

` `

return 0;

}

“%d” and “%i” are *format specifiers* for the integer data type.

The division operator only gives the quotient, so you need a different operator to find the remainder. That operator is the *modulus operator*, denoted by the “%” symbol.

Replacing the **division operator (/)** with the **modulus operator (%)** in the above code segment as follows:

c = a % b;

will give 4 as the result of the modulus operation—which is the remainder of the division problem.

## Float Division

In float division, either or both of the operands are of the float data type. That is:

- a float type dividend is divided by an integer type divisor, or
- an integer type dividend is divided by a float type divisor, or
- a float type dividend is divided by a float type divisor to produce a float type quotient.

Consider the division problem of distributing $36 equally among eight people. How much money does each person get? The answer is $4.50.

That’s what float division does; it gives a quotient with a decimal point.

The following C++ code segment demonstrates this:

` `

#include <iostream>

using namespace std;

int main()

{

` `

float num1 = 36;

` `

float num2 = 8;

` `

float result = num1 / num2;

` `

cout<<quotient;

` `

return 0;

}

This code, compiled using a standard C++ compiler, will result in 4.5 as the output.

In the above example, variables “num1”, “num2” and “result” are all of the float data type. Here:

- “num1”—which we call the dividend—is the left operand for the division operation.
- “num2”—which we call the divisor—is the right operand for the division operation.
- The result of the operation gives a value, that is stored in the variable “result.”

Lets' see how can we write it in C language:

#include <stdio.h>

int main()

{

float a = 36;

float b = 8;

float c = a / b;

printf ("%f",c);

return 0;

}

“%f” is the format specifier for the float data type.

Why is the output “4.500000” and not just “4.5”?

The reason is that the precision of the “float” data type—as listed in the table with the size and range of the three float data types—is up to six decimal points.

To get “4.5” as the output, you write **“%.1f”** in place of **“%f”** in the print f() statement.

## Precedence and Associativity of the Division Operator

When two operators with different precedence are adjacent to each other in an expression, which operator should be evaluated first is based on the **operator precedence** rule. The rule says the division operator has the same precedence as the multiplication and modulus operators. However, it has lower precedence than the unary operators—Postfix, Prefix, Bitwise NOT and Logical NOT.

When two operators with the same precedence are adjacent to each other in an expression, which operator should be evaluated first is based on **associative rules**—which tell the compiler whether it should evaluate from left to right (**LR**) or from right to left (**RL**). The associativity of the division operator is LR.

## Technical Language/Glossary

Data type | An attribute of data that tells the compiler the type of data intended to be stored in the computer. The primary or fundamental data types are integer type, floating point type, character type and void. |

Integer | A datatype which stores whole numbers only. |

Float | A datatype which stores any real number up to 6 decimal points. |

Double | A datatype which stores any real number up to 10 decimal points. |

Modulus | An arithmetic operator which helps to find the remainder after division. |

Precedence | When two operators with different precedence are adjacent to each other in an expression, which operator should be evaluated first is based on the operator precedence rule. |

Associativity | When two operators with the same precedence are adjacent to each other in an expression, which operator should be evaluated first is based on associative rules. |

## Concept and Applications

This topic is significant for learning basics of programming and it is also important in the professional exams for undergraduate courses, especially for:

- B. Tech in Computer science
- B. Tech in Computer engineering
- B. Tech in Information Technology
- B. E in Computer science
- B. E in Computer engineering
- B. E in Information Technology
- Bachelor of Computer Applications (BCA)

### Want more help with your computer science homework?

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

### Search. Solve. Succeed!

Study smarter access to millions of step-by step textbook solutions, our Q&A library, and AI powered Math Solver. Plus, you get 30 questions to ask an expert each month.

# Division Operator Homework Questions from Fellow Students

Browse our recently answered Division Operator homework questions.

### Search. Solve. Succeed!

Study smarter access to millions of step-by step textbook solutions, our Q&A library, and AI powered Math Solver. Plus, you get 30 questions to ask an expert each month.