Arithmetic Operators
Explore Dart's arithmetic operators to perform basic math operations, apply the unary minus for sign changes, and use prefix and postfix increments. Understand how these operators evaluate expressions and update variables dynamically.
We'll cover the following...
Arithmetic operators perform mathematical operations such as addition and subtraction. Below is a list of the arithmetic operators supported by Dart.
Operator | Use |
| Adds two operands |
| Subtracts the second operand from the first |
| Reverses the sign of the expression (unary minus) |
| Multiplies both operands |
| Divides the first operand by the second operand |
| Divides the first operand by the second operand and returns an integer by truncating toward zero |
| Gets the remainder after division of one number by another |
Most of the operators behave identically to standard mathematics. The truncating division operator (~/) divides both operands and removes the fractional part from the decimal value.
We can observe how the basic operators process numeric values in the following file.
Lines 5—8: We perform standard mathematical operations including addition, subtraction, multiplication, and standard division.
Line 10: We use the truncating division operator (
~/) to divide 10 by 7. This drops the fractional part and evaluates to 1.Line 11: ...